Another update... the check_icmp routine was consuming a lot of bandwidth to my host and needlessly cluttering my logs so I move the routine so it only gets executed if the check_http routine detects a problem.
#!/bin/bash
#
# Filename: /root/monitor.sh
#
# Purpose: Perform a service check of the HTTP process by connecting to
# the port utilizing the Nagios plug-in check_http
#
# Language: Bash Script
#
# Author: Michael McNamara
#
# Verzion: 0.4
#
# Date: Feb 21, 2011
#
# Changes:
# Mar 17, 2011 moved check_icmp routine so it executes only if
# the check_http routine detects a failure, this
# should cut down on the large ICMP overhead
# Mar 07, 2011 added check_icmp routine to script
# Mar 06, 2011 fixed email notification
# Feb 23, 2011 cleaned up script/updated documentation
#
# Requirements:
#
# Nagios check_icmp plugin
# Nagios check_http plugin
# http://nagiosplugins.org/man/check_http
#
# Notes:
# Command Line Reference;
# ./monitor.sh
#
#
# Declare Variables
SENDMAIL="/bin/mail"
CHECK_HTTP="/root/check_http"
CHECK_ICMP="/root/check_icmp"
LOG="/var/log/check_http.log"
MAIL_TO="root"
MAIL_SUBJECT="Server Host check script report"
DATETIME=`date`
# Site specific information
HOST1="blog.michaelfmcnamara.com"
URL1="/"
STRING1="Disclaimer"
HOST2="forums.networkinfrastructure.info"
URL2="/"
STRING2="SMF"
########################################################################
########################################################################
#
# Loop1 for blog.michaelfmcnamara.com
#
PING1="`${CHECK_ICMP} ${HOST1}`"
RESULT1="`${CHECK_HTTP} -H ${HOST1} -s ${STRING1}`"
# Debug output
if [[ $RESULT1 =~ "OK" ]]
then
echo $DATETIME OK $HOST1 $RESULT1 >> $LOG
else
echo $RESULT1 | $SENDMAIL -s "$MAIL_SUBJECT" $MAIL_TO
echo $DATETIME FAIL $HOST1 $RESULT1 >> $LOG
PING1="`${CHECK_ICMP} ${HOST1}`"
if [[ $PING1 =~ "OK" ]]
then
echo $DATETIME OK $HOST1 $PING1 >> $LOG
else
echo $PING1 | $SENDMAIL -s "$MAIL_SUBJECT" $MAIL_TO
echo $DATETIME FAIL $HOST1 $PING1 >> $LOG
fi
fi
#
# Loop2 for forums.networkinfrastructure.info
#
RESULT2="`${CHECK_HTTP} -H ${HOST2} -s ${STRING2}`"
# Debug output
#echo RESULT $HOST2 = ${RESULT2}
if [[ $RESULT2 =~ "OK" ]]
then
echo $DATETIME OK $HOST2 $RESULT2>> $LOG
else
echo $RESULT2 | $SENDMAIL -s "$MAIL_SUBJECT" $MAIL_TO
echo $DATETIME FAIL $HOST2 $RESULT2 >> $LOG
PING2="`${CHECK_ICMP} ${HOST2}`"
if [[ $PING2 =~ "OK" ]]
then
echo $DATETIME OK $HOST2 $PING2 >> $LOG
else
echo $PING2 | $SENDMAIL -s "$MAIL_SUBJECT" $MAIL_TO
echo $DATETIME FAIL $HOST2 $PING2 >> $LOG
fi
fi
exit 0