try {
	var creds = JSON.parse(value);
}
catch (error) {
	throw 'Failed to parse authentication data from input value.';
}

var request = new HttpRequest(),
	pods = [],
	error_msg = '',
	url = '{$PURE.FLASHARRAY.API.URL}',
	version = '{$PURE.FLASHARRAY.API.VERSION}',
	http_proxy = '{$PURE.FLASHARRAY.HTTP_PROXY}';

function getHttpData(url, cookie) {
	request.addHeader('Cookie: ' + cookie);
	response = request.get(url);
	Zabbix.log(4, '[ Pure Storage API ] [ ' + url + ' ] Received response with status code ' + request.getStatus() + ': ' + response);

	if (request.getStatus() !== 200) {
		throw 'Failed to receive data: invalid response status code.';
	}

	if (response !== null) {
		try {
			response = JSON.parse(response);
		}
		catch (error) {
			throw 'Failed to parse response received from Pure Storage API. Check debug log for more information.';
		}
	}

	if (typeof response !== 'object' || response === null) {
		throw 'Cannot process response data: received data is not an object.';
	}

	return response;
};

try {

	['cookie'].forEach(function (field) {
		if (creds[field] === null || creds[field] == '' || typeof creds[field] === 'undefined') {
			throw 'Unexpected cookie value has been received'
			+ ((typeof creds.error !== 'undefined' && creds.error != '') ? ': ' + creds.error : '');
		}
	});

	if (url === '{' + '$PURE.FLASHARRAY.API.URL}') {
		throw 'Please change {' + '$PURE.FLASHARRAY.API.URL} macro to the proper value.';
	}

	if (url.indexOf('http://') === -1 && url.indexOf('https://') === -1) {
		url = 'https://' + url + (!url.endsWith('/') ? '/' : '');
	}

	if (http_proxy !== '{' + '$PURE.FLASHARRAY.HTTP_PROXY}' && http_proxy !== '') {
		request.setProxy(http_proxy);
	}

	pods = getHttpData(
		url + 'api/' + version + '/pod',
		creds.cookie
	);

} catch (err) {
	error_msg = err;
};

return JSON.stringify({
	'pods': pods,
	'error': error_msg.toString()
});