Template for Generic Nagios Plugin | blog.jgriffiths.org
I love nagios it’s the perfect way to monitor linux. Monitoring command can be written in almost any language: nagios expects a exit code and a exit string and it works. I write most of my plugins in bash shell. Here is a generic plugin template:
#!/bin/bash
# Sanity check
if [ $# -ne 2 ]; then
echo « Usage: $0 commandline1 commandline2″
exit
fi
COMMAND=`command_here`
E_SUCCESS= »0″
E_WARNING= »1″
E_CRITICAL= »2″
E_UNKNOWN= »3 »
if grep -q « succeeded! » <<< $COMMAND; then echo "OK - $1 $2 working" exit ${E_SUCCESS} else echo "CRITICAL - $1 $2 not working" exit ${E_CRITICAL} fi © 2010, Joseph Griffiths. All rights reserved.