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', 'path', 'user', 'password', 'http_status_code'], params);
var dell = new Dell('Network Interface', 'Get metrics', params);

const keys = [
	{
		'name': 'linkStatus',
		'path': 'LinkStatus'
	},
	{
		'name': 'health',
		'path': 'Status.Health'
	},
	{
		'name': 'state',
		'path': 'Status.State'
	},
	{
		'name': 'linkSpeed',
		'path': 'CurrentLinkSpeedMbps'
	}
];

return JSON.stringify(dell.extractData(dell.executeRequest(params.path), keys));