Hey,
I've got some issues on Integrating the Meraki Dashboard into the Zabbix.
I get allways following error when I Test my template: "Failed to parse response received from Meraki API. Check debug log for more information." The specific Error is the following "SyntaxError: invalid json (at offset 1)"
It would be great if someone could help me while finding a solution.
Is there a possibility to Debug these Item directly in Zabbix?
Thank you very much
Arne
I've got some issues on Integrating the Meraki Dashboard into the Zabbix.
I get allways following error when I Test my template: "Failed to parse response received from Meraki API. Check debug log for more information." The specific Error is the following "SyntaxError: invalid json (at offset 1)"
Code:
var params = JSON.parse(value);
var request = new HttpRequest();
request.addHeader('X-Cisco-Meraki-API-Key:' + params.token);
request.addHeader('User-Agent: ZabbixServer/1.1 Zabbix');
var response,
error_msg = '',
organizations = [],
devices = [],
network_id = "",
network_name = "",
networks = [],
organization = [];
function getHttpData(url) {
response = request.get(url);
Zabbix.log(4, '[ Meraki API ] [ ' + url + ' ] Received response with status code ' + request.getStatus() + ': ' + response);
if (response !== null) {
if (typeof (response) !== 'object'){
try {
response = JSON.parse(response);
}
catch (error) {
throw 'Failed to parse response received from Meraki API. Check debug log for more information.';
}
}
}
if (request.getStatus() !== 200) {
if (response.errors) {
throw response.errors.join(', ');
} else {
throw 'Failed to receive data: invalid response status code.';
}
}
if (typeof (response) !== 'object' || response === null) {
throw 'Cannot process response data: received data is not an object.';
}
return response;
};
try {
if (params.token === '{' + '$MERAKI.TOKEN}') {
throw 'Please change {' + '$MERAKI.TOKEN} macro to the proper value.';
}
if (params.url.indexOf('http://') === -1 && params.url.indexOf('https://') === -1) {
params.url = 'https://' + params.url;
}
if (!params.url.endsWith('/')) {
params.url += '/';
}
if (typeof params.httpproxy !== 'undefined' && params.httpproxy !== '') {
request.setProxy(params.httpproxy);
}
organizations = getHttpData(params.url + 'organizations');
if (Array.isArray(organizations) && organizations.length > 0) {
for (i in organizations) {
if ('id' in organizations[i]) {
organization_networks = getHttpData(params.url + 'organizations/' + encodeURIComponent(organizations[i].id) + '/networks');
if (Array.isArray(organization_networks) && organization_networks.length > 0) {
for (y in organization_networks) {
if ('id' in organization_networks[y]) {
if ((organization_networks[y].id === params.networkid) || organization_networks[y].name === params.networkname) {
network_id = organization_networks[y].id;
network_name = organization_networks[y].name
}
}
}
organization_devices = getHttpData(params.url + 'organizations/' + encodeURIComponent(organizations[i].id) + '/devices/statuses');
if (Array.isArray(organization_devices) && organization_devices.length > 0) {
for (j in organization_devices) {
if (organization_devices[j].networkId === network_id) {
organization_devices[j].organizationId = organizations[i].id;
if (!organization_devices[j].name) {
organization_devices[j].name = organization_devices[j].serial;
}
if (!organization_devices[j].networkname) {
organization_devices[j].networkName = network_name;
}
organization[0] = organizations[i];
networks[0] = getHttpData(params.url + 'organizations/' + encodeURIComponent(organizations[i].id) + '/networks/' + network_id);
devices.push(organization_devices[j]);
}
}
}
}
}
}
}
} catch (error) {
error_msg = error;
};
return JSON.stringify({
'organizations': organization,
'networks': networks,
'devices': devices,
'error': error_msg.toString()
});
Is there a possibility to Debug these Item directly in Zabbix?
Thank you very much
Arne