Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
I'm trying to configure a bash script to be run with nagios plugin - check_by_ssh. The is to check if a process (I've used syslogd here) is running or not after ssh'ing into the server with "check_by_ssh" plugin. If running/sleeping the script will return 0. Else if the process has T or Z state, the script will return 1, else the script exits with exit 2. The final aim is to display the status of process as as ok,warn or critical on the nagios web interface.
#!/bin/bash
pid=`/sbin/pidof syslogd`
if /sbin/pidof syslogd &> /dev/null; then
while read name first rest; do
if [[ $name = "State:" ]] ; then state="$first"; break;
fi;
done </proc/$pid/status;
case "$state" in
S|R|D) #echo "Running fine"
exit 0
;;
T|Z) #echo "Some problem"
exit 1
;;
esac
else
#echo "Process does not exist"
exit 2;
fi
When i run the bash script locally on the destination server, I get returned the exact status code of the process being checked. But it fails when I run as mentioned above. If I uncomment the 'echo' lines in the script, I get returned "Running fine" as the result of above command. Is my approach correct here in this case?