#!/bin/sh

###############################################################
# NetSaint Global Service 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 = service description
# $4 = state
# $5 = state type (HARD or SOFT)
# $6 = current attempt number
#
#########################################

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

case $5 in

    HARD)
	case $4 in
	    OK)
		$echocmd "Good news!  Service $3 on $2 has RECOVERED!" > $speechdev
		;;
	    CRITICAL)
		$echocmd "Attention. . .  Service $3 on $2 is in a $4 state.  Please check service!" > $speechdev
		;;
	    WARNING)
		$echocmd "Attention. . .  Service $3 on $2 is in a $4 state.  Please check service!" > $speechdev
		;;
	    UNKNOWN)
		$echocmd "Attention. . .  Service $3 on $2 is in a $4 state.  Please check service!" > $speechdev
		;;
	esac
	;;

    # Getting audio feedback when service 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 services are in soft states.
    SOFT)
	case $4 in
	    OK)
		;;
	    CRITICAL)
		$echocmd "Attention.  Service $3 on $2 is in a $5 $4 state." > $speechdev
		;;
	    WARNING)
		$echocmd "Attention.  Service $3 on $2 is in a $5 $4 state." > $speechdev
		;;
	    UNKNOWN)
		$echocmd "Attention.  Service $3 on $2 is in a $5 $4 state." > $speechdev
		;;
	esac
	;;
esac

exit 0