Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Directory
swardks
byswardks, September 16, 2017
This article was easy enough to follow. I have the check_meraki_status file added to /usr/local/nagios/libexec with same permissions as all other files, code pasted in file, and configured on two hosts, each with one service check.
When executing the check, the information only returns the results of the code minus the first line.
Current Status: OK (for 0d 0h 10m 37s)
Status Information: // $argv[1] is the MAC Address specified on the host definition file for the device,
// if specified run code, otherwise, print error message and exit with "Code 3" = "Unknown"
if (isset($argv[1])) {
// The Meraki Cloud Controller uses a Decimal format of the MAC Address for its SNMP Queries,
// here we are converting the MAC Address (XX:XX:XX:XX:XX:XX) to Decimal (X.X.X.X.X.X.X)
$macAddress = HexToDecConverter(':', '.', $argv[1]);
// Get the name and status from the Meraki Cloud Controller for device identified by newly converted MAC Address
$devStatus = shell_exec('/usr/local/bin/snmpwalk -c "Put Your Meraki Cloud Community String Here" -v2c snmp.meraki.com:16100 1.3.6.1.4.1.29671.1.1.4.1.3.' . $macAddress);
$devName = shell_exec('/usr/local/bin/snmpwalk -c "Put Your Meraki Cloud Community String Here" -v2c snmp.meraki.com:16100 1.3.6.1.4.1.29671.1.1.4.1.2.' . $macAddress);
// Extract the device name from the snmpwalk result, the returned string will be as follows => STRING: "Device Name"
$str = $devName;
preg_match('/"(.*?)"/', $str, $match);
$devName = $match['1'];
switch ($devStatus) {
// Perform a search on the snmpwalk result for device status, the returned string will be as follows => INTEGER: X
// If "1" is found on the string, print "Device Name is Online" and Exit with "Code 0" = "OK"
case (strpos($devStatus, 'INTEGER: 1') !== FALSE):
print $devName . ' is Online';
EXIT(0);
break;
// if "0" is found on the string, print "Device Name is Offline" and Exit with "Code 2" = "Critical"
case (strpos($devStatus, 'INTEGER: 0') !== FALSE):
print $devName . ' is Offline';
EXIT(2);
break;
default:
}
} else {
print 'MAC Argument Not Provided';
EXIT(3);
}
// Function to convert MAC Addresses from Hexadecimal (XX.XX.XX.XX.XX.XX) to Decimal Format (X.X.X.X.X.X), you need to provide
// the 2 delimeters and the MAC Address you'd like to convert.
// $explodeDelimiter is the delimeter of the original MAC Address, in our case is ":"
// $implodeDelimiter is the delimeter we want to print on the new MAC Address, in our case is "."
function HexToDecConverter($explodeDelimiter, $implodeDelimiter, $mac) {
$macOctects = explode($explodeDelimiter, $mac);
foreach ($macOctects as &$octects) {
$octects = hexdec($octects);
}
unset($octects);
return join($implodeDelimiter, $macOctects);
}
Performance Data:
Current Attempt: 1/3 (HARD state)
Last Check Time: 09-16-2017 16:57:20
Check Type: ACTIVE
Check Latency / Duration: 0.000 / 0.009 seconds
Next Scheduled Check: 09-16-2017 17:07:20
Last State Change: 09-16-2017 16:51:27
Last Notification: N/A (notification 0)
Is This Service Flapping? NO (11.84% state change)
In Scheduled Downtime? NO
Last Update: 09-16-2017 17:01:57 ( 0d 0h 0m 7s ago)
Any idea what is causing this? I reviewed the other files though they were all perl so could not verify syntax for Nagios.
Thanks!
When executing the check, the information only returns the results of the code minus the first line.
Current Status: OK (for 0d 0h 10m 37s)
Status Information: // $argv[1] is the MAC Address specified on the host definition file for the device,
// if specified run code, otherwise, print error message and exit with "Code 3" = "Unknown"
if (isset($argv[1])) {
// The Meraki Cloud Controller uses a Decimal format of the MAC Address for its SNMP Queries,
// here we are converting the MAC Address (XX:XX:XX:XX:XX:XX) to Decimal (X.X.X.X.X.X.X)
$macAddress = HexToDecConverter(':', '.', $argv[1]);
// Get the name and status from the Meraki Cloud Controller for device identified by newly converted MAC Address
$devStatus = shell_exec('/usr/local/bin/snmpwalk -c "Put Your Meraki Cloud Community String Here" -v2c snmp.meraki.com:16100 1.3.6.1.4.1.29671.1.1.4.1.3.' . $macAddress);
$devName = shell_exec('/usr/local/bin/snmpwalk -c "Put Your Meraki Cloud Community String Here" -v2c snmp.meraki.com:16100 1.3.6.1.4.1.29671.1.1.4.1.2.' . $macAddress);
// Extract the device name from the snmpwalk result, the returned string will be as follows => STRING: "Device Name"
$str = $devName;
preg_match('/"(.*?)"/', $str, $match);
$devName = $match['1'];
switch ($devStatus) {
// Perform a search on the snmpwalk result for device status, the returned string will be as follows => INTEGER: X
// If "1" is found on the string, print "Device Name is Online" and Exit with "Code 0" = "OK"
case (strpos($devStatus, 'INTEGER: 1') !== FALSE):
print $devName . ' is Online';
EXIT(0);
break;
// if "0" is found on the string, print "Device Name is Offline" and Exit with "Code 2" = "Critical"
case (strpos($devStatus, 'INTEGER: 0') !== FALSE):
print $devName . ' is Offline';
EXIT(2);
break;
default:
}
} else {
print 'MAC Argument Not Provided';
EXIT(3);
}
// Function to convert MAC Addresses from Hexadecimal (XX.XX.XX.XX.XX.XX) to Decimal Format (X.X.X.X.X.X), you need to provide
// the 2 delimeters and the MAC Address you'd like to convert.
// $explodeDelimiter is the delimeter of the original MAC Address, in our case is ":"
// $implodeDelimiter is the delimeter we want to print on the new MAC Address, in our case is "."
function HexToDecConverter($explodeDelimiter, $implodeDelimiter, $mac) {
$macOctects = explode($explodeDelimiter, $mac);
foreach ($macOctects as &$octects) {
$octects = hexdec($octects);
}
unset($octects);
return join($implodeDelimiter, $macOctects);
}
Performance Data:
Current Attempt: 1/3 (HARD state)
Last Check Time: 09-16-2017 16:57:20
Check Type: ACTIVE
Check Latency / Duration: 0.000 / 0.009 seconds
Next Scheduled Check: 09-16-2017 17:07:20
Last State Change: 09-16-2017 16:51:27
Last Notification: N/A (notification 0)
Is This Service Flapping? NO (11.84% state change)
In Scheduled Downtime? NO
Last Update: 09-16-2017 17:01:57 ( 0d 0h 0m 7s ago)
Any idea what is causing this? I reviewed the other files though they were all perl so could not verify syntax for Nagios.
Thanks!