#!/bin/sh

###############################################################
# NetSaint Global Host Event Handler
#
# Note: This event handler script is intended to serve as an
# example of how to produce audio alerts when NetSaint detects
# network problems.  Read the HTML documentation for more
# information on event handlers and how this script works.
#
# Arguments:
#
# $1 = host short name
# $2 = host alias (long name)
# $3 = state
# $4 = state type (HARD or SOFT)
# $5 = current attempt number
#
###############################################################

echocmd="/bin/echo"
speechdev="/dev/speech"

case $4 in

    HARD)
	case $3 in
	    UP)
		$echocmd "Good news!  Host $2 has RECOVERED!" > $speechdev
		;;
	    DOWN)
		$echocmd "Attention...  Host $2 is $3.  This is a critical state. Please check host status!" > $speechdev
		;;
	    UNREACHABLE)
		$echocmd "Attention...  Host $2 is $3.  This is a critical state.  Please check network connectivity!" > $speechdev
		;;
	esac
	;;

    # Getting audio feedback when host checks are being retried gives you additional time to
    # fix the problem, but it can get really annoying sometimes.  As such, you may not want
    # any alerts while hosts are in soft states.
    SOFT)
	case $3 in
	    UP)
		;;
	    DOWN)
		$echocmd "Attention... Host $2 is in a $4 $3 state.  Attempt number $5" > $speechdev
		;;
	    UNREACHABLE)
		$echocmd "Attention... Host $2 is in a $4 $3 state.  Attempt number $5" > $speechdev
		;;
	esac
	;;
esac

exit 0
