Custom Nagios Plugin

We have a custom nagios plugin that someone wrote for our previous NMS system that works with it but not libre. We use this to check to see when our PMP 450 AP’s lose GPS sync, and need to be reset via the synconboard command. I believe this was a bug in a prior version of the PMP 450 firmware that has been fixed but we would like to keep this checking this in the future. The problem is even though when the script is run from the command line it works and outputs the correct information but when run through the services it doesn’t. The original script and check-services.php output.

#!/bin/bash

gettimingstatus=$(snmpget -v2c -cCanopy $1 1.3.6.1.4.1.161.19.3.1.3.2.0 | awk '{print $4}')
finalvalue=$(echo $gettimingstatus | sed  's/\"//g' | sed 's/Power/1/g' | sed 's/Timing/2/g' | sed 's/On\-board/3/g')
echo 'OK|Timing='$finalvalue

https://p.libren.ms/view/ce55ee8b

librenms@xxxx:~$ /usr/lib/nagios/plugins/check_timing_status 10.10.144.4
OK|Timing=3

So I did a bit of googling and updated the script to be the following.

#!/bin/bash

gettimingstatus=$(snmpget -v2c -cCanopy $1 1.3.6.1.4.1.161.19.3.1.3.2.0 | awk '{print $4}')
finalvalue=$(echo $gettimingstatus | sed  's/\"//g' | sed 's/Power/1/g' | sed 's/Timing/2/g' | sed 's/On\-board/3/g')
if [[ $finalvalue == "3" ]]; then
  echo 'CRITICAL|Timing=3'
  exit 3
elif [[ $finalvalue == "2" ]]; then
  echo 'WARNING|Timing=2'
  exit 2
else
  echo 'OK|Timing=1'
  exit 1
fi

Now it’s seeing the value for the graph from the script but still not seeing the error’d state.
https://p.libren.ms/view/ac2b1006
librenms@xxxx:~$ /usr/lib/nagios/plugins/check_timing_status 10.10.144.4
CRITICAL|Timing=3

I suspect it’s just in the way the script is written but I’m at a loss at this point, so I figured I’d ask some folks with a bit more knowledge.

The host you pass to it must have it passed as -h 10.10.144.4 or you need to create a custom includes/services/check_timing_status.inc.php file (look at others for ideas) which will drop the -h requirement.

Worked like a charm. Thanks!