function validateZabbixParams(requiredParams, allParams) {
	requiredParams.forEach(function (field) {
		if (typeof allParams !== 'object' || typeof allParams[field] === 'undefined' || allParams[field] === '') {
			throw 'Required param is not set: ' + field + '.';
		}
	});
}

function Dell(service, action, params) {
	this.zabbixLogPrefix = '[ DELL ] [ ' + service + ' ] [ ' + action + ' ]';
	this.request = new HttpRequest();

	this.executeRequest = function (apiPath) {
		this.request.addHeader('Authorization: Basic ' + btoa(params['user'] + ':' + params['password']));

		if (params['http_proxy']) {
			this.request.setProxy(params['http_proxy']);
			Zabbix.log(4, this.zabbixLogPrefix + ' Using http proxy: ' + params['http_proxy']);
		}

		const response = this.request.get(params['url'] + apiPath);

		this.request.clearHeader();

		if (this.request.getStatus() === parseInt(params['http_status_code'])) {
			return response;
		} else {
			Zabbix.log(3, this.zabbixLogPrefix + ' Unexpected HTTP response code: ' + this.request.getStatus());
			throw 'Unexpected HTTP response code: ' + this.request.getStatus();
		}
	};

	this.extractData = function (data, keys, skipParse) {
		if (!skipParse) {
			try {
				data = JSON.parse(data);
			} catch (error) {
				Zabbix.log(3, this.zabbixLogPrefix + ' Could not parse the received JSON object: ' + data);
				throw 'Could not parse received JSON object. See logs for more information.';
			}	
		}

		if (Array.isArray(keys)) {
			var returnBuffer = {};

			for (keyIdx = 0, keysLength = keys.length; keyIdx < keysLength; keyIdx++) {
				if (keys[keyIdx]['path'] === '@odata.id') {
					returnBuffer[keys[keyIdx]['name']] = data[keys[keyIdx]['path']];
				} else {
					returnBuffer[keys[keyIdx]['name']] = this.parseJSON(data, keys[keyIdx]['path'].split('.'));
				}
			}

			return returnBuffer;
		} else if (typeof keys === 'object') {
			return { [keys['name']]: this.parseJSON(data, keys['path'].split('.')) };
		} else if (typeof keys === 'string') {
			return this.parseJSON(data, keys.split('.'));
		} else {
			throw 'Unexpected key type';
		}
	};

	this.parseJSON = function (data, jsonPath) {
		for (var i = 0, args = jsonPath.length; i < args; i++) {
			data = data[jsonPath[i]];
		}

		return data;
	}
}


const params = JSON.parse(value);

validateZabbixParams(['url', 'user', 'password', 'http_status_code'], params);
var dell = new Dell('Disk', 'Discovery', params);

const disks = dell.extractData(dell.executeRequest('/redfish/v1/Systems/System.Embedded.1/Storage'), 'Members');

var keys = [
	{
		'name': 'path',
		'path': '@odata.id'
	},
	{
		'name': 'name',
		'path': 'Name'
	}
];

if (!Array.isArray(disks)) {
	throw 'Unexpected type for disks.';
}

var buffer = { 'physicalDisks': [], 'virtualDisks': [] };

disks.forEach(function (disk) {
	var requests = [{ 'usage': 'physicalDisks', 'path': '', 'target': 'Drives' }, { 'usage': 'virtualDisks', 'path': '/Volumes', 'target': 'Members' }];

	requests.forEach(function (request) {
		const disks = dell.extractData(dell.executeRequest(disk['@odata.id'] + request['path']), request['target']);

		if (!Array.isArray(disks) || disks.length <= 0) {
			return;
		}

		disks.forEach(function (drive) {
			buffer[request['usage']].push(dell.extractData(dell.executeRequest(drive['@odata.id']), keys));
		});
	});
});

return JSON.stringify(buffer);