always remember

Nothing is foolproof to a sufficiently talented fool... Make something
idiot proof, and the world will simply make a bigger idiot.

Monitor Daemonized FastNetMon Process in Debian (Nagios NRPE)

Running FastNetmon on a Debian system to monitor traffic flow on your network? Need a solution to monitor if the fastnetmon daemonized process ever crashes? Me neither until today… Here you go.

#!/bin/bash
#
#Check ps aux returns correct number of lines (process running)
PROCESS=`ps aux | grep fastnetmon | grep -v grep | grep -v check_fastnetmon`
granular=`ps aux | grep fastnetmon | grep -v grep | grep -v check_fastnetmon | awk '{print $2}'`
#echo $PROCESS
echo "$PROCESS" > /var/lib/nagios/tempoutput
LINES=`wc -l /var/lib/nagios/tempoutput | awk '{print $1}'`
#echo $LINES
#echo $granular
re='^[0-9]+$'
if [[ $granular =~ $re ]] ;
then
  #Get the PID
  PID=`ps aux | grep fastnetmon | grep -v grep | grep -v check_fastnetmon | awk '{print $2}'`
  #Echo and Exit
  echo "OK - FastNetmon running. PID:"$PID
  exit 0
else
  #Echo and Exit
  echo "CRITICAL - FastNetmon NOT running. NO PID!"
  exit 2
fi
rm -rf /var/lib/nagios/tempoutput

Notes:
– Code above is new as of 11/04/2016. If you downloaded/used prior to this date, please replace code with the above. Previous versions of the code have a rather serious bug in where process failures are sometimes not detected, as the check will deted te PID of the actual nagios check being run at the time as a valid FastNewMon process ID… The new version avoids this.
– If you run multiple fastnetmon processes, you will need to tweak the -gt value in the logic
– Requires sudo to be installed, requires the nagios user to have execute ability on the script

dave / April 6, 2016 / Code, Nagios Monitoring
Tags: , , ,