Build precise queries to find exactly what you need
Press ESC to close
Your review has been submitted and is pending approval.
This plugin will query the Meraki Cloud controller and return user friendly messages to be displayed by the Nagios Server.
Current Version
1
Last Release Date
August 16, 2017
Owner
Sergio Hernandez
Compatible With
Requirements 1 - The MAC Address of the device you want to monitor.
************************************************************* How to use
1 - Create a new file named "check_meraki_status" on "/usr/local/nagios/libexec" and paste the code below, make sure to verify permissions for the new file:
#!/usr/bin/php <?php // $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); } ?>
****************************************************** 2 - Define a new command on your objects folder:
# 'check_meraki_status' command definition define command{ command_name check_meraki_status command_line $USER1$/check_meraki_status $ARG1$ }
3- Define a new service for the host you want to monitor:
# Meraki Controller Device Status define service { use generic-service host_name "Your host name" service_description Meraki Status check_command check_meraki_status! "Your Host MAC Address" }
4 - Check you Nagios Server to see if the plugin is working. I have this working on Core 4.3.1 and XI.
there are mainly 4 status options: offline alerting, online and dormant. The plugin always shows online if not offline
is necessary insert n/php
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!
You must be logged in to submit a review.
To:
From: