function request(url) {
    api_request = new HttpRequest();
    api_request.addHeader('Authorization: Basic ' + btoa(params.user + ':' + params.password));
    Zabbix.log(4, '[ DELL ] Sending request: ' + url);

    try {
        response = api_request.get(url);
    } catch (error) {
        Zabbix.log(4, '[ DELL ] Get request returned error ' + error);
        throw 'Get request returned error ' + error + '. Check debug log for more information.';
    }

    Zabbix.log(4, '[ DELL ] Received response with status code ' +
        api_request.getStatus() + '\n' + response);

    if (api_request.getStatus() !== 200) {
        var message = 'Request failed with status code ' + api_request.getStatus();
        if (response !== null) {
            if (typeof response.message === 'string') {
                message += ': ' + response.message;
            }
        }

        throw message + ' Check debug log for more information.';
    }

    if (response !== null) {
        try {
            response = JSON.parse(response);
        }
        catch (error) {
            Zabbix.log(4, '[ DELL ] Failed to parse response.');
            response = null;
        }
    }

    return {
        status: api_request.getStatus(),
        body: response
    };
}

function getField(object, field, def) {
    var names = field.split('.');
    var name = names.shift();

    while (typeof name !== 'undefined') {
        if (typeof object === undefined || typeof object[name] === 'undefined') {
            return def;
        }

        object = object[name];
        name = names.shift();
    }

    return object;
}

try {
    adapters = JSON.parse(value);
}
catch (error) {
    Zabbix.log(4, '[ DELL ] Failed to parse response.');
    adapters = null;
}

var params = {
    url: '{$API.URL}',
    user: '{$API.USER}',
    password: '{$API.PASSWORD}'
};
var result = [];

var index = params.url.indexOf('://');
index = params.url.indexOf('/', (index !== -1) ? (index + 3) : 0);
if (index !== -1) {
    params.url = params.url.substring(0, index);
}

if (adapters.Members instanceof Array) {
    adapters.Members.forEach(function (adapter) {
        if (typeof adapter["@odata.id"] === 'string') {
            response = request(params.url + adapter["@odata.id"] + "/NetworkPorts");
            ports = response.body;
            if (ports.Members instanceof Array) {
                ports.Members.forEach(function (port) {
                    if (typeof port["@odata.id"] === 'string') {
                        response = request(params.url + port["@odata.id"]);
                        result.push({ '{#IFNAME}': getField(response.body, 'Id', ''), '{#ODATA}': port["@odata.id"] });
                    }
                });
            }
        }
    });
}

return JSON.stringify(result);