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 {
	sensors = JSON.parse(value);
}
catch (error) {
	Zabbix.log(4, '[ DELL ] Failed to parse response.');
	sensors = 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 (sensors.Members instanceof Array) {
	sensors.Members.forEach(function (sensor) {
		if (typeof sensor["@odata.id"] === 'string') {
			response = request(params.url + sensor["@odata.id"]);
			if (getField(response.body, 'ReadingType', '') === 'Voltage') {
				result.push({ '{#SENSOR_NAME}': getField(response.body, 'Name', ''), '{#ODATA}': sensor["@odata.id"] });
			}
		}
	});
}

return JSON.stringify(result);