#!/bin/sh # Service checking utility # Requires NetCat # Run from cron. # creates a lot of files...sorry # 2003 William H. Backman # 2014 William H. Backman - Added html output # 2016 WHB - Temp change to use ping # 1 of 4: PUT YOUR E-MAIL ADDRESS HERE # SET to "" to disable email. NOTIFY="" # 2 of 4: DIRECTORY TO OUTPUT FILES OUTPUT="$HOME/html/flap" # Begin Building the html file. cat << EOF > $OUTPUT/flap.html ^v^v Flap Host Monitor

^v^v Flap Host Monitor

EOF DATE=`date` # 3 of 4: URL FOR STATUS WEB PAGE SENT TO EMAIL URL="http://bitgeist.freeshell.org/flap/flap.html" # 4 of 4: ADD YOUR HOST AND PORT for SERVICE in \ "fc.aos92.org" \ "moodle.aos92.org" \ "www.aos92.org" \ "destiny.wtvl.k12.me.us" \ do # NO NEED TO MODIFY ANYTHING BELOW # Check to see if a state file exists already if [ -f "$OUTPUT/$SERVICE" ]; then STATE=`cat "$OUTPUT/$SERVICE"` else STATE="first check" fi # NetCat does the work here. # nc -w 3 -z $SERVICE # Changed to use ping here ping -c 3 $SERVICE if [ $? -eq 0 ]; then CATSTATE="success" echo $CATSTATE > "$OUTPUT/$SERVICE" echo ''>> $OUTPUT/flap.html else CATSTATE="failure" echo $CATSTATE > "$OUTPUT/$SERVICE" echo ''>> $OUTPUT/flap.html fi # compare the old state to the current if [ "$STATE" != "$CATSTATE" ]; then echo $DATE State change: "$SERVICE" $STATE to $CATSTATE >> $OUTPUT/flap-log.txt if [ "$NOTIFY" != "" ]; then echo State change: "$SERVICE" $STATE to $CATSTATE "\n" $URL | mail -s "$SERVICE $CATSTATE" $NOTIFY fi fi done # Finish writing the html file cat << FEOF >> $OUTPUT/flap.html
'Up: $SERVICE '
'Dn: $SERVICE '

Log File

Page generated on $DATE

FEOF