1177 lines
42 KiB
YAML
1177 lines
42 KiB
YAML
zabbix_export:
|
|
version: '7.0'
|
|
template_groups:
|
|
- uuid: a571c0d144b14fd4a87a9d9b2aa9fcd6
|
|
name: Templates/Applications
|
|
- uuid: 36bff6c29af64692839d077febfc7079
|
|
name: 'Templates/Network devices'
|
|
templates:
|
|
- uuid: 2cae7d2eeca04e6fa7419759ac9ad814
|
|
template: 'Cisco Meraki device by HTTP'
|
|
name: 'Cisco Meraki device by HTTP'
|
|
description: 'Generated by official Zabbix template tool "Templator"'
|
|
vendor:
|
|
name: Zabbix
|
|
version: 7.0-6
|
|
groups:
|
|
- name: Templates/Applications
|
|
- name: 'Templates/Network devices'
|
|
items:
|
|
- uuid: a45187d4bd154072bc75d76df09708d9
|
|
name: 'Device address'
|
|
type: DEPENDENT
|
|
key: meraki.device.address
|
|
delay: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
description: |
|
|
Device location address
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: LOCATION
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.address
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: 92b275569cff4013b545b5c251a318ab
|
|
name: Firmware
|
|
type: DEPENDENT
|
|
key: meraki.device.firmware
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Device firmware
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: SOFTWARE
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.firmware
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: 0c97a8fcad764133b4e7c35d0134665c
|
|
name: 'Get status'
|
|
type: SCRIPT
|
|
key: meraki.device.get.status
|
|
delay: '{$MERAKI.GET.STATUS.INTERVAL}'
|
|
history: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
params: |
|
|
const CTlsConfig = function (raw_value) {
|
|
raw_value = String(raw_value).trim().toLowerCase();
|
|
|
|
if (['none', 'peer', 'full'].indexOf(raw_value) === -1) {
|
|
raw_value = 'full';
|
|
}
|
|
|
|
this.options = {
|
|
SSLVerifyPeer: (raw_value === 'peer' || raw_value === 'full'),
|
|
SSLVerifyHost: (raw_value === 'full')
|
|
};
|
|
|
|
this.enabled = (raw_value !== 'none');
|
|
|
|
this.checkURL = function (url) {
|
|
if (this.enabled && !/^https:\/\//i.test(url)) {
|
|
throw 'TLS certificate verification is enabled by {$' + 'HTTP.TLS.VERIFY}, but the URL uses plain HTTP: ' + url +
|
|
'. Use an "https://" URL, or set {$' + 'HTTP.TLS.VERIFY} to `none` to disable verification.';
|
|
}
|
|
|
|
return url;
|
|
};
|
|
}
|
|
|
|
|
|
var params = JSON.parse(value);
|
|
|
|
var tls = new CTlsConfig(params.tls_verify);
|
|
|
|
var request = new HttpRequest(tls.options);
|
|
|
|
request.addHeader('X-Cisco-Meraki-API-Key:' + params.token);
|
|
request.addHeader('User-Agent: ZabbixServer/1.2 Zabbix');
|
|
|
|
function hasHeader(headers, name) {
|
|
if (typeof headers !== 'object' || headers === null) {
|
|
return false;
|
|
}
|
|
|
|
var target = name.toLowerCase();
|
|
|
|
for (var key in headers) {
|
|
if (key.toLowerCase() === target) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function parseTime(timeString) {
|
|
var match = timeString.match(/^(\d+)([h|m|s])$/);
|
|
if (match) {
|
|
var value = parseInt(match[1], 10);
|
|
var unit = match[2];
|
|
|
|
switch (unit) {
|
|
case 'h':
|
|
return value * 3600;
|
|
case 'm':
|
|
return value * 60;
|
|
case 's':
|
|
return value;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
};
|
|
|
|
var response,
|
|
error_msg = '',
|
|
response = [],
|
|
timespan;
|
|
|
|
function getHttpData(url) {
|
|
var startTime = new Date().getTime();
|
|
var maxWait = parseInt(timespan, 10) * 1000;
|
|
var waitFor = 1000;
|
|
|
|
while (true) {
|
|
response = request.get(url);
|
|
Zabbix.log(4, '[ Meraki API ] [ ' + url + ' ] Received response with status code ' + request.getStatus() + ': ' + response);
|
|
|
|
var status = request.getStatus();
|
|
|
|
if (response !== null) {
|
|
try {
|
|
response = JSON.parse(response);
|
|
}
|
|
catch (error) {
|
|
throw 'Failed to parse response received from Meraki API. Check debug log for more information.';
|
|
}
|
|
}
|
|
|
|
if (status === 429 && response && response.errors && Array.isArray(response.errors) &&
|
|
response.errors.indexOf("API rate limit exceeded for organization") !== -1) {
|
|
var now = new Date().getTime();
|
|
var headers = request.getHeaders(false);
|
|
|
|
if (hasHeader(headers, 'Retry-After')) {
|
|
var retryAfter = headers['Retry-After'];
|
|
Zabbix.log(4, '[ Meraki API ] API rate limit exceeded. Retrying after ' + retryAfter + ' seconds.');
|
|
waitFor = parseInt(retryAfter) * 1000;
|
|
}
|
|
else {
|
|
Zabbix.log(4, '[ Meraki API ] API rate limit exceeded. No Retry-After header. Retrying after 1 second.');
|
|
}
|
|
if (now - startTime + waitFor > maxWait) {
|
|
throw 'Failed to receive data: API rate limit exceeded and retry timeout reached.';
|
|
}
|
|
Zabbix.sleep(waitFor);
|
|
continue;
|
|
}
|
|
|
|
if (status !== 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 += '/';
|
|
}
|
|
|
|
tls.checkURL(params.url);
|
|
|
|
if (typeof params.httpproxy !== 'undefined' && params.httpproxy !== '') {
|
|
request.setProxy(params.httpproxy);
|
|
}
|
|
|
|
timespan = parseTime('{$MERAKI.GET.STATUS.INTERVAL}');
|
|
|
|
response = getHttpData(params.url + 'organizations/' + encodeURIComponent(params.organizationId) + '/devices/availabilities?serials[]=' + encodeURIComponent(params.serial));
|
|
if (Array.isArray(response) & response.length > 0) {
|
|
response = response[0]
|
|
}
|
|
|
|
} catch (error) {
|
|
error_msg = error;
|
|
};
|
|
|
|
return JSON.stringify({
|
|
'data': response,
|
|
'error': error_msg.toString()
|
|
});
|
|
description: 'Item for gathering device status from Meraki API.'
|
|
timeout: '{$MERAKI.DATA.TIMEOUT}'
|
|
parameters:
|
|
- name: httpproxy
|
|
value: '{$MERAKI.HTTP_PROXY}'
|
|
- name: organizationId
|
|
value: '{$ORGANIZATION_ID}'
|
|
- name: serial
|
|
value: '{$SERIAL}'
|
|
- name: tls_verify
|
|
value: '{$HTTP.TLS.VERIFY:"Cisco Meraki device"}'
|
|
- name: token
|
|
value: '{$MERAKI.TOKEN}'
|
|
- name: url
|
|
value: '{$MERAKI.API.URL}'
|
|
tags:
|
|
- tag: component
|
|
value: raw
|
|
- uuid: b1873bc0a185452dbede07373e0e4a93
|
|
name: 'Device status item errors'
|
|
type: DEPENDENT
|
|
key: meraki.device.get.status.errors
|
|
delay: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
description: 'Item for gathering errors of the device status item.'
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.error
|
|
- type: DISCARD_UNCHANGED_HEARTBEAT
|
|
parameters:
|
|
- 1h
|
|
master_item:
|
|
key: meraki.device.get.status
|
|
tags:
|
|
- tag: component
|
|
value: error
|
|
triggers:
|
|
- uuid: 0f629d0aef6b456fb3d5b1a20ece54ac
|
|
expression: 'length(last(/Cisco Meraki device by HTTP/meraki.device.get.status.errors))>0'
|
|
name: 'Meraki: There are errors in ''Get status'' metric'
|
|
priority: WARNING
|
|
tags:
|
|
- tag: scope
|
|
value: availability
|
|
- uuid: 878cbc22039b4fab9949c1997041b1a8
|
|
name: 'Device latitude'
|
|
type: DEPENDENT
|
|
key: meraki.device.latitude
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Latitude of the device location
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: LOCATION_LAT
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.lat
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: de69a544bf9047da9f47b0b8f6c61bf2
|
|
name: 'Device longitude'
|
|
type: DEPENDENT
|
|
key: meraki.device.longitude
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Longitude of the device location
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: LOCATION_LON
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.lng
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: 3867fdab6af941ab9958b05b197419df
|
|
name: 'MAC address'
|
|
type: DEPENDENT
|
|
key: meraki.device.mac.address
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Device MAC address
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: MACADDRESS_A
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.mac
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: network
|
|
- uuid: e66780872dba46dc9265c4dad022a799
|
|
name: 'Device model'
|
|
type: DEPENDENT
|
|
key: meraki.device.model
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Device model
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: MODEL
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.model
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: 514db363389741619b3103fd57ec0675
|
|
name: 'Device notes'
|
|
type: DEPENDENT
|
|
key: meraki.device.notes
|
|
delay: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
description: |
|
|
Notes about the device
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: NOTES
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.notes
|
|
error_handler: DISCARD_VALUE
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: 9c36f19a2d72418dbef579142722372f
|
|
name: 'Device OS'
|
|
type: DEPENDENT
|
|
key: meraki.device.os
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Device operation system
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: OS
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- '$.deviceInfo.details[0].value'
|
|
error_handler: DISCARD_VALUE
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: 2280b9212c474d99835ec1334ff780eb
|
|
name: 'Public IP'
|
|
type: DEPENDENT
|
|
key: meraki.device.public.ip
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Device public IP
|
|
Network: {$NETWORK.ID}
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.ip
|
|
- type: NOT_MATCHES_REGEX
|
|
parameters:
|
|
- ^null$
|
|
error_handler: DISCARD_VALUE
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: network
|
|
- uuid: fa98beea4eca47859cc53a7d6bcf2008
|
|
name: 'Serial number'
|
|
type: DEPENDENT
|
|
key: meraki.device.serialnumber
|
|
delay: '0'
|
|
value_type: CHAR
|
|
trends: '0'
|
|
description: |
|
|
Device serial number
|
|
Network: {$NETWORK.ID}
|
|
inventory_link: SERIALNO_A
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.deviceInfo.serial
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: system
|
|
- uuid: 324b748bfe2e4383927176046e246acb
|
|
name: Status
|
|
type: DEPENDENT
|
|
key: meraki.device.status
|
|
delay: '0'
|
|
description: |
|
|
Device operational status
|
|
Network: {$NETWORK.ID}
|
|
valuemap:
|
|
name: 'Device status'
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.data.status
|
|
error_handler: DISCARD_VALUE
|
|
- type: JAVASCRIPT
|
|
parameters:
|
|
- |
|
|
switch (value) {
|
|
case 'offline':
|
|
return 0
|
|
case 'online':
|
|
return 1
|
|
case 'dormant':
|
|
return 2
|
|
case 'alerting':
|
|
return 3
|
|
default:
|
|
return 10
|
|
}
|
|
master_item:
|
|
key: meraki.device.get.status
|
|
tags:
|
|
- tag: component
|
|
value: health
|
|
triggers:
|
|
- uuid: 00583ac9e9824f7db12a1685421f0be9
|
|
expression: 'last(/Cisco Meraki device by HTTP/meraki.device.status)=3'
|
|
name: 'Meraki: Status is alerting'
|
|
priority: WARNING
|
|
tags:
|
|
- tag: scope
|
|
value: availability
|
|
- uuid: 00583ac9e9824f7db22a1685421f0be9
|
|
expression: 'last(/Cisco Meraki device by HTTP/meraki.device.status)=0'
|
|
name: 'Meraki: Status is offline'
|
|
priority: AVERAGE
|
|
tags:
|
|
- tag: scope
|
|
value: availability
|
|
- uuid: e4963b68cdde453f91767ff9e3a31d16
|
|
name: 'Get device data'
|
|
type: SCRIPT
|
|
key: meraki.get.device
|
|
delay: '{$MERAKI.UPLINK.LL.TIMESPAN}'
|
|
history: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
params: |
|
|
const CTlsConfig = function (raw_value) {
|
|
raw_value = String(raw_value).trim().toLowerCase();
|
|
|
|
if (['none', 'peer', 'full'].indexOf(raw_value) === -1) {
|
|
raw_value = 'full';
|
|
}
|
|
|
|
this.options = {
|
|
SSLVerifyPeer: (raw_value === 'peer' || raw_value === 'full'),
|
|
SSLVerifyHost: (raw_value === 'full')
|
|
};
|
|
|
|
this.enabled = (raw_value !== 'none');
|
|
|
|
this.checkURL = function (url) {
|
|
if (this.enabled && !/^https:\/\//i.test(url)) {
|
|
throw 'TLS certificate verification is enabled by {$' + 'HTTP.TLS.VERIFY}, but the URL uses plain HTTP: ' + url +
|
|
'. Use an "https://" URL, or set {$' + 'HTTP.TLS.VERIFY} to `none` to disable verification.';
|
|
}
|
|
|
|
return url;
|
|
};
|
|
}
|
|
|
|
|
|
var params = JSON.parse(value);
|
|
|
|
var tls = new CTlsConfig(params.tls_verify);
|
|
|
|
var request = new HttpRequest(tls.options);
|
|
|
|
request.addHeader('X-Cisco-Meraki-API-Key:' + params.token);
|
|
request.addHeader('User-Agent: ZabbixServer/1.2 Zabbix');
|
|
|
|
var response,
|
|
error_msg = '',
|
|
device = [],
|
|
uplinksLL = [],
|
|
timespan;
|
|
|
|
function isFloat(n) {
|
|
n = parseFloat(n);
|
|
return Number(n) === n && n % 1 !== 0;
|
|
};
|
|
|
|
function checkNumber(string) {
|
|
if (typeof string !== "string" || isNaN(string) || isFloat(string)) {
|
|
throw 'Incorrect "timespan" parameter given: ' + string + ' Must be an unsigned number';
|
|
}
|
|
return string;
|
|
};
|
|
|
|
function hasHeader(headers, name) {
|
|
if (typeof headers !== 'object' || headers === null) {
|
|
return false;
|
|
}
|
|
|
|
var target = name.toLowerCase();
|
|
|
|
for (var key in headers) {
|
|
if (key.toLowerCase() === target) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function getHttpData(url) {
|
|
var startTime = new Date().getTime();
|
|
var maxWait = (parseInt(timespan, 10) - 10) * 1000;
|
|
var waitFor = 1000;
|
|
|
|
while (true) {
|
|
response = request.get(url);
|
|
Zabbix.log(4, '[ Meraki API ] [ ' + url + ' ] Received response with status code ' + request.getStatus() + ': ' + response);
|
|
|
|
var status = request.getStatus();
|
|
|
|
if (response !== null) {
|
|
try {
|
|
response = JSON.parse(response);
|
|
}
|
|
catch (error) {
|
|
throw 'Failed to parse response received from Meraki API. Check debug log for more information.';
|
|
}
|
|
}
|
|
|
|
if (status === 429 && response && response.errors && Array.isArray(response.errors) &&
|
|
response.errors.indexOf("API rate limit exceeded for organization") !== -1) {
|
|
var now = new Date().getTime();
|
|
var headers = request.getHeaders(false);
|
|
|
|
if (hasHeader(headers, 'Retry-After')) {
|
|
var retryAfter = headers['Retry-After'];
|
|
Zabbix.log(4, '[ Meraki API ] API rate limit exceeded. Retrying after ' + retryAfter + ' seconds.');
|
|
waitFor = parseInt(retryAfter) * 1000;
|
|
}
|
|
else {
|
|
Zabbix.log(4, '[ Meraki API ] API rate limit exceeded. No Retry-After header. Retrying after 1 second.');
|
|
}
|
|
if (now - startTime + waitFor > maxWait) {
|
|
throw 'Failed to receive data: API rate limit exceeded and retry timeout reached.';
|
|
}
|
|
Zabbix.sleep(waitFor);
|
|
continue;
|
|
}
|
|
|
|
if (status !== 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 += '/';
|
|
}
|
|
|
|
tls.checkURL(params.url);
|
|
|
|
if (typeof params.httpproxy !== 'undefined' && params.httpproxy !== '') {
|
|
request.setProxy(params.httpproxy);
|
|
}
|
|
|
|
timespan = checkNumber('{$MERAKI.UPLINK.LL.TIMESPAN}');
|
|
|
|
if (timespan > 86400 || timespan < 1) {
|
|
throw 'Incorrect "timespan" parameter given: ' + timespan + ' Must be between 1 and 86400 seconds.';
|
|
}
|
|
|
|
uplinksLL = getHttpData(params.url + 'organizations/' + encodeURIComponent(params.organizationId) + '/devices/uplinksLossAndLatency?timespan=' + timespan);
|
|
|
|
if (uplinksLL.length > 0) {
|
|
uplinksLL = uplinksLL.filter(function (device) {
|
|
return device.serial == params.serial;
|
|
});
|
|
}
|
|
|
|
} catch (error) {
|
|
error_msg = error;
|
|
};
|
|
|
|
return JSON.stringify({
|
|
'uplinksLL': uplinksLL,
|
|
'error': error_msg.toString()
|
|
});
|
|
description: 'Item for gathering device data from Meraki API.'
|
|
timeout: '{$MERAKI.DATA.TIMEOUT}'
|
|
parameters:
|
|
- name: httpproxy
|
|
value: '{$MERAKI.HTTP_PROXY}'
|
|
- name: organizationId
|
|
value: '{$ORGANIZATION_ID}'
|
|
- name: serial
|
|
value: '{$SERIAL}'
|
|
- name: tls_verify
|
|
value: '{$HTTP.TLS.VERIFY:"Cisco Meraki device"}'
|
|
- name: token
|
|
value: '{$MERAKI.TOKEN}'
|
|
- name: url
|
|
value: '{$MERAKI.API.URL}'
|
|
tags:
|
|
- tag: component
|
|
value: raw
|
|
- uuid: b673516073354c9aaaf60cf3ce2e2fa6
|
|
name: 'Device data item errors'
|
|
type: DEPENDENT
|
|
key: meraki.get.device.errors
|
|
delay: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
description: 'Item for gathering errors of the device item.'
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.error
|
|
- type: DISCARD_UNCHANGED_HEARTBEAT
|
|
parameters:
|
|
- 1h
|
|
master_item:
|
|
key: meraki.get.device
|
|
tags:
|
|
- tag: component
|
|
value: error
|
|
triggers:
|
|
- uuid: c8f8af6c92f14dc0bcdf426b124c7344
|
|
expression: 'length(last(/Cisco Meraki device by HTTP/meraki.get.device.errors))>0'
|
|
name: 'Meraki: There are errors in ''Get device data'' metric'
|
|
priority: WARNING
|
|
tags:
|
|
- tag: scope
|
|
value: availability
|
|
- uuid: ae461bc520a840d9b0f0847011f52bce
|
|
name: 'Get inventory data'
|
|
type: SCRIPT
|
|
key: meraki.get.inventory
|
|
delay: '{$MERAKI.GET.INVENTORY.INTERVAL}'
|
|
history: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
params: |
|
|
const CTlsConfig = function (raw_value) {
|
|
raw_value = String(raw_value).trim().toLowerCase();
|
|
|
|
if (['none', 'peer', 'full'].indexOf(raw_value) === -1) {
|
|
raw_value = 'full';
|
|
}
|
|
|
|
this.options = {
|
|
SSLVerifyPeer: (raw_value === 'peer' || raw_value === 'full'),
|
|
SSLVerifyHost: (raw_value === 'full')
|
|
};
|
|
|
|
this.enabled = (raw_value !== 'none');
|
|
|
|
this.checkURL = function (url) {
|
|
if (this.enabled && !/^https:\/\//i.test(url)) {
|
|
throw 'TLS certificate verification is enabled by {$' + 'HTTP.TLS.VERIFY}, but the URL uses plain HTTP: ' + url +
|
|
'. Use an "https://" URL, or set {$' + 'HTTP.TLS.VERIFY} to `none` to disable verification.';
|
|
}
|
|
|
|
return url;
|
|
};
|
|
}
|
|
|
|
|
|
var params = JSON.parse(value);
|
|
|
|
var tls = new CTlsConfig(params.tls_verify);
|
|
|
|
var request = new HttpRequest(tls.options);
|
|
|
|
request.addHeader('X-Cisco-Meraki-API-Key:' + params.token);
|
|
request.addHeader('User-Agent: ZabbixServer/1.2 Zabbix');
|
|
|
|
function hasHeader(headers, name) {
|
|
if (typeof headers !== 'object' || headers === null) {
|
|
return false;
|
|
}
|
|
|
|
var target = name.toLowerCase();
|
|
|
|
for (var key in headers) {
|
|
if (key.toLowerCase() === target) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function parseTime(timeString) {
|
|
var match = timeString.match(/^(\d+)([h|m|s])$/);
|
|
if (match) {
|
|
var value = parseInt(match[1], 10);
|
|
var unit = match[2];
|
|
|
|
switch (unit) {
|
|
case 'h':
|
|
return value * 3600;
|
|
case 'm':
|
|
return value * 60;
|
|
case 's':
|
|
return value;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
};
|
|
|
|
var response,
|
|
error_msg = '',
|
|
deviceInfo = [],
|
|
timespan;
|
|
|
|
function getHttpData(url) {
|
|
var startTime = new Date().getTime();
|
|
var maxWait = parseInt(timespan, 10) * 1000;
|
|
var waitFor = 1000;
|
|
|
|
while (true) {
|
|
response = request.get(url);
|
|
Zabbix.log(4, '[ Meraki API ] [ ' + url + ' ] Received response with status code ' + request.getStatus() + ': ' + response);
|
|
|
|
var status = request.getStatus();
|
|
|
|
if (response !== null) {
|
|
try {
|
|
response = JSON.parse(response);
|
|
}
|
|
catch (error) {
|
|
throw 'Failed to parse response received from Meraki API. Check debug log for more information.';
|
|
}
|
|
}
|
|
|
|
if (status === 429 && response && response.errors && Array.isArray(response.errors) &&
|
|
response.errors.indexOf("API rate limit exceeded for organization") !== -1) {
|
|
var now = new Date().getTime();
|
|
var headers = request.getHeaders(false);
|
|
|
|
if (hasHeader(headers, 'Retry-After')) {
|
|
var retryAfter = headers['Retry-After'];
|
|
Zabbix.log(4, '[ Meraki API ] API rate limit exceeded. Retrying after ' + retryAfter + ' seconds.');
|
|
waitFor = parseInt(retryAfter) * 1000;
|
|
}
|
|
else {
|
|
Zabbix.log(4, '[ Meraki API ] API rate limit exceeded. No Retry-After header. Retrying after 1 second.');
|
|
}
|
|
if (now - startTime + waitFor > maxWait) {
|
|
throw 'Failed to receive data: API rate limit exceeded and retry timeout reached.';
|
|
}
|
|
Zabbix.sleep(waitFor);
|
|
continue;
|
|
}
|
|
|
|
if (status !== 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 += '/';
|
|
}
|
|
|
|
tls.checkURL(params.url);
|
|
|
|
if (typeof params.httpproxy !== 'undefined' && params.httpproxy !== '') {
|
|
request.setProxy(params.httpproxy);
|
|
}
|
|
|
|
timespan = parseTime('{$MERAKI.GET.INVENTORY.INTERVAL}');
|
|
|
|
deviceInfo = getHttpData(params.url + 'organizations/' + encodeURIComponent(params.organizationId) + '/devices?serial=' + encodeURIComponent(params.serial));
|
|
deviceInfo = (deviceInfo && Array.isArray(deviceInfo) && deviceInfo.length > 0) ? deviceInfo[0] : [];
|
|
deviceInfo['ip'] = (typeof deviceInfo.lanIp !== 'undefined') ? deviceInfo['lanIp'] : deviceInfo['wan1Ip'];
|
|
|
|
} catch (error) {
|
|
error_msg = error;
|
|
};
|
|
|
|
return JSON.stringify({
|
|
'deviceInfo': deviceInfo,
|
|
'error': error_msg.toString()
|
|
});
|
|
description: 'Item for gathering device inventory data from Meraki API.'
|
|
timeout: '{$MERAKI.DATA.TIMEOUT}'
|
|
parameters:
|
|
- name: httpproxy
|
|
value: '{$MERAKI.HTTP_PROXY}'
|
|
- name: organizationId
|
|
value: '{$ORGANIZATION_ID}'
|
|
- name: serial
|
|
value: '{$SERIAL}'
|
|
- name: tls_verify
|
|
value: '{$HTTP.TLS.VERIFY:"Cisco Meraki device"}'
|
|
- name: token
|
|
value: '{$MERAKI.TOKEN}'
|
|
- name: url
|
|
value: '{$MERAKI.API.URL}'
|
|
tags:
|
|
- tag: component
|
|
value: raw
|
|
- uuid: eb8c1772e6b940998b5eaa9fc95f92a5
|
|
name: 'Device inventory data item errors'
|
|
type: DEPENDENT
|
|
key: meraki.get.inventory.errors
|
|
delay: '0'
|
|
value_type: TEXT
|
|
trends: '0'
|
|
description: 'Item for gathering errors of the inventory data item.'
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.error
|
|
- type: DISCARD_UNCHANGED_HEARTBEAT
|
|
parameters:
|
|
- 1h
|
|
master_item:
|
|
key: meraki.get.inventory
|
|
tags:
|
|
- tag: component
|
|
value: error
|
|
triggers:
|
|
- uuid: af0fa91e3e03415683c3fa2761ad7328
|
|
expression: 'length(last(/Cisco Meraki device by HTTP/meraki.get.inventory.errors))>0'
|
|
name: 'Meraki: There are errors in ''Get inventory data'' metric'
|
|
priority: WARNING
|
|
tags:
|
|
- tag: scope
|
|
value: availability
|
|
discovery_rules:
|
|
- uuid: 9c7e5d2ccad7416b8d58237be4218154
|
|
name: 'Uplinks loss and quality discovery'
|
|
type: DEPENDENT
|
|
key: meraki.device.uplinks.discovery
|
|
delay: '0'
|
|
filter:
|
|
evaltype: AND
|
|
conditions:
|
|
- macro: '{#IP}'
|
|
value: '{$MERAKI.DEVICE.LOSS.LATENCY.IP.MATCHES}'
|
|
formulaid: A
|
|
- macro: '{#IP}'
|
|
value: '{$MERAKI.DEVICE.LOSS.LATENCY.IP.NOT_MATCHES}'
|
|
operator: NOT_MATCHES_REGEX
|
|
formulaid: B
|
|
- macro: '{#UPLINK}'
|
|
value: '{$MERAKI.DEVICE.UPLINK.MATCHES}'
|
|
formulaid: C
|
|
- macro: '{#UPLINK}'
|
|
value: '{$MERAKI.DEVICE.UPLINK.NOT_MATCHES}'
|
|
operator: NOT_MATCHES_REGEX
|
|
formulaid: D
|
|
item_prototypes:
|
|
- uuid: abf642b1bb944d16bebf90dcf58dbd86
|
|
name: 'Uplink [{#IP}]: [{#UPLINK}]: Latency'
|
|
type: DEPENDENT
|
|
key: 'meraki.device.latency[{#IP},{#UPLINK}]'
|
|
delay: '0'
|
|
value_type: FLOAT
|
|
units: s
|
|
description: |
|
|
Latency of the device uplink.
|
|
Network: {#NETWORK.ID}.
|
|
Device serial: {#SERIAL}.
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- '$.uplinksLL[?(@.ip == ''{#IP}'' && @.uplink== ''{#UPLINK}'')].timeSeries.[0].latencyMs.first()'
|
|
error_handler: CUSTOM_VALUE
|
|
error_handler_params: '-1000'
|
|
- type: MULTIPLIER
|
|
parameters:
|
|
- '0.001'
|
|
master_item:
|
|
key: meraki.get.device
|
|
tags:
|
|
- tag: component
|
|
value: network
|
|
- tag: ip
|
|
value: '{#IP}'
|
|
- tag: network
|
|
value: '{#NETWORK.ID}'
|
|
- tag: serial-number
|
|
value: '{#SERIAL}'
|
|
- tag: uplink
|
|
value: '{#UPLINK}'
|
|
trigger_prototypes:
|
|
- uuid: b559ad94b15848089d89e85e4d9db7ff
|
|
expression: 'min(/Cisco Meraki device by HTTP/meraki.device.latency[{#IP},{#UPLINK}],#3)>{$MERAKI.DEVICE.LATENCY}'
|
|
name: 'Meraki: Uplink [{#IP}]: [{#UPLINK}]: latency > {$MERAKI.DEVICE.LATENCY}'
|
|
priority: WARNING
|
|
tags:
|
|
- tag: scope
|
|
value: performance
|
|
- uuid: bded34f64113486ab0672210e5a8eb1d
|
|
name: 'Uplink [{#IP}]: [{#UPLINK}]: Loss, %'
|
|
type: DEPENDENT
|
|
key: 'meraki.device.loss.pct[{#IP},{#UPLINK}]'
|
|
delay: '0'
|
|
value_type: FLOAT
|
|
units: '%'
|
|
description: |
|
|
Loss percent of the device uplink.
|
|
Network: {#NETWORK.ID}.
|
|
Device serial: {#SERIAL}.
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- '$.uplinksLL[?(@.ip == ''{#IP}'' && @.uplink== ''{#UPLINK}'')].timeSeries.[0].lossPercent.first()'
|
|
error_handler: CUSTOM_VALUE
|
|
error_handler_params: '-1'
|
|
master_item:
|
|
key: meraki.get.device
|
|
tags:
|
|
- tag: component
|
|
value: network
|
|
- tag: ip
|
|
value: '{#IP}'
|
|
- tag: network
|
|
value: '{#NETWORK.ID}'
|
|
- tag: serial-number
|
|
value: '{#SERIAL}'
|
|
- tag: uplink
|
|
value: '{#UPLINK}'
|
|
trigger_prototypes:
|
|
- uuid: 1309e71025614ce4bb4242e6e291ae48
|
|
expression: 'min(/Cisco Meraki device by HTTP/meraki.device.loss.pct[{#IP},{#UPLINK}],#3)>{$MERAKI.DEVICE.LOSS}'
|
|
name: 'Meraki: Uplink [{#IP}]: [{#UPLINK}]: loss > {$MERAKI.DEVICE.LOSS}%'
|
|
priority: WARNING
|
|
tags:
|
|
- tag: scope
|
|
value: performance
|
|
graph_prototypes:
|
|
- uuid: 4e9d84e08b32489c8c3a2cbbd4c6119a
|
|
name: 'Uplink [{#IP}]: [{#UPLINK}]: Latency'
|
|
ymin_type_1: FIXED
|
|
graph_items:
|
|
- color: 199C0D
|
|
item:
|
|
host: 'Cisco Meraki device by HTTP'
|
|
key: 'meraki.device.latency[{#IP},{#UPLINK}]'
|
|
- uuid: ebf262afc6d94d29b9831d418fb07edb
|
|
name: 'Uplink [{#IP}]: [{#UPLINK}]: Loss'
|
|
ymin_type_1: FIXED
|
|
graph_items:
|
|
- color: 199C0D
|
|
item:
|
|
host: 'Cisco Meraki device by HTTP'
|
|
key: 'meraki.device.loss.pct[{#IP},{#UPLINK}]'
|
|
master_item:
|
|
key: meraki.get.device
|
|
lld_macro_paths:
|
|
- lld_macro: '{#IP}'
|
|
path: $.ip
|
|
- lld_macro: '{#NETWORK.ID}'
|
|
path: $.networkId
|
|
- lld_macro: '{#SERIAL}'
|
|
path: $.serial
|
|
- lld_macro: '{#UPLINK}'
|
|
path: $.uplink
|
|
preprocessing:
|
|
- type: JSONPATH
|
|
parameters:
|
|
- $.uplinksLL
|
|
tags:
|
|
- tag: class
|
|
value: network
|
|
- tag: target
|
|
value: cisco-meraki-dashboard
|
|
macros:
|
|
- macro: '{$HTTP.TLS.VERIFY}'
|
|
value: full
|
|
description: 'TLS certificate verification for script items: "none" - disabled, "peer" - verify the certificate chain and expiration, "full" - full verification. Any other value enables full verification. To override the setting for this template only, define the macro with the context "Cisco Meraki device", e.g. {$HTTP.TLS.VERIFY:"Cisco Meraki device"}.'
|
|
- macro: '{$MERAKI.API.URL}'
|
|
value: api.meraki.com/api/v1
|
|
description: 'Cisco Meraki dashboard API URL, e.g., api.meraki.com/api/v1'
|
|
- macro: '{$MERAKI.DATA.TIMEOUT}'
|
|
value: '60'
|
|
description: 'Response timeout for an API.'
|
|
- macro: '{$MERAKI.DEVICE.LATENCY}'
|
|
value: '0.15'
|
|
description: 'Devices uplink latency threshold, in seconds.'
|
|
- macro: '{$MERAKI.DEVICE.LOSS}'
|
|
value: '15'
|
|
description: 'Devices uplink loss threshold, in percent.'
|
|
- macro: '{$MERAKI.DEVICE.LOSS.LATENCY.IP.MATCHES}'
|
|
value: '^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$'
|
|
description: 'This macro is used in loss and latency checks discovery. Can be overridden on the host or linked template level.'
|
|
- macro: '{$MERAKI.DEVICE.LOSS.LATENCY.IP.NOT_MATCHES}'
|
|
value: ^null$
|
|
description: 'This macro is used in loss and latency checks discovery. Can be overridden on the host or linked template level.'
|
|
- macro: '{$MERAKI.DEVICE.UPLINK.MATCHES}'
|
|
value: '.*'
|
|
description: 'This macro is used in loss and latency checks discovery. Can be overridden on the host or linked template level.'
|
|
- macro: '{$MERAKI.DEVICE.UPLINK.NOT_MATCHES}'
|
|
value: ^null$
|
|
description: 'This macro is used in loss and latency checks discovery. Can be overridden on the host or linked template level.'
|
|
- macro: '{$MERAKI.GET.INVENTORY.INTERVAL}'
|
|
value: 12h
|
|
description: 'The update interval for the script item that retrieves inventory data from API.'
|
|
- macro: '{$MERAKI.GET.STATUS.INTERVAL}'
|
|
value: '300'
|
|
description: 'Update interval for get status item.'
|
|
- macro: '{$MERAKI.HTTP_PROXY}'
|
|
description: 'HTTP proxy for API requests. You can specify it using the format [protocol://][username[:password]@]proxy.example.com[:port]. See documentation at https://www.zabbix.com/documentation/7.0/manual/config/items/itemtypes/http'
|
|
- macro: '{$MERAKI.TOKEN}'
|
|
type: SECRET_TEXT
|
|
description: 'Cisco Meraki dashboard API token.'
|
|
- macro: '{$MERAKI.UPLINK.LL.TIMESPAN}'
|
|
value: '180'
|
|
description: 'Timespan in seconds for getting device uplinks loss and quality stats. Used in the metric configuration and in the JavaScript API query. Must be between 1 and 86400 seconds.'
|
|
dashboards:
|
|
- uuid: 76c4525eacc64f268572fefd76accc2f
|
|
name: 'Meraki: General'
|
|
pages:
|
|
- name: 'Meraki: Uplinks'
|
|
widgets:
|
|
- type: graphprototype
|
|
name: Loss
|
|
width: '36'
|
|
height: '5'
|
|
fields:
|
|
- type: INTEGER
|
|
name: columns
|
|
value: '1'
|
|
- type: GRAPH_PROTOTYPE
|
|
name: graphid.0
|
|
value:
|
|
host: 'Cisco Meraki device by HTTP'
|
|
name: 'Uplink [{#IP}]: [{#UPLINK}]: Loss'
|
|
- type: STRING
|
|
name: reference
|
|
value: AAAAA
|
|
- type: graphprototype
|
|
name: Latency
|
|
x: '36'
|
|
width: '36'
|
|
height: '5'
|
|
fields:
|
|
- type: INTEGER
|
|
name: columns
|
|
value: '1'
|
|
- type: GRAPH_PROTOTYPE
|
|
name: graphid.0
|
|
value:
|
|
host: 'Cisco Meraki device by HTTP'
|
|
name: 'Uplink [{#IP}]: [{#UPLINK}]: Latency'
|
|
- type: STRING
|
|
name: reference
|
|
value: AAAAB
|
|
valuemaps:
|
|
- uuid: 24967dff65a048578eae18b2485907cb
|
|
name: 'Device status'
|
|
mappings:
|
|
- value: '0'
|
|
newvalue: offline
|
|
- value: '1'
|
|
newvalue: online
|
|
- value: '2'
|
|
newvalue: dormant
|
|
- value: '3'
|
|
newvalue: alerting
|
|
- value: '10'
|
|
newvalue: unknown
|