Who watches the watchman - err... Nagios? Part II

As many people only read my RSS content feed (but not the comment feed) I decieded to repeat this script here as new content ;-)

The previous solution has some drawbacks (only one check, so sometimes you get false negatives). So here we go:

!/bin/sh

CMD="/usr/lib/nagios/plugins/check_nagios -F /var/cache/nagios3/status.dat -e 1 -C nagios3"
EMAIL=foobar@...spambox.com

OUTCHECK=$CMD

if [ $? -ne 0 ]
then
sleep 300
OUTCHECK=$CMD
if [ $? -ne 0 ]
then
OUTPROC=ps ax | grep "/usr/sbin/nagios3" | grep -v grep
if [ $? -eq 0 ]
then
(
echo -e "Output of check_nagios_check:\n| $OUTCHECK\n\n"
echo -e "Output of ps:\n| $OUTPROC"
) | /usr/bin/mail -s "[NAGIOS] Log file stale, but process found" $EMAIL
else
(
echo -e "Output of check_nagios_check:\n| $OUTCHECK\n\n"
echo "NO output of ps, Nagios process is NOT running"
) | /usr/bin/mail -s "[NAGIOS] Log file stale, NO process found" $EMAIL
fi
fi
fi

exit 0

Same script (hope so...) in german/Script mit deutschen Ausgaben