#!/bin/sh

# REDUNDANCY EVENT HANDLER SCRIPT
# Written By: Ethan Galstad (netsaint@linuxbox.com)
# Last Modified: 01-14-2000
#
# This is an example script for implementing redundancy.
# Read the HTML documentation on redundant monitoring for more
# information on what this does.

# Location of the echo and mail commands
echocmd="/bin/echo"
mailcmd="/bin/mail"

# Location of the event handlers
eventhandlerdir="/usr/local/netsaint/libexec/eventhandlers"


# Only take action on hard host states...
case "$2" in
HARD)

	case "$1" in
	DOWN)
		# The master host has gone down!
		# We should now become the master host and take
		# over the responsibilities of monitoring the 
		# network, so enter active mode...

		`$eventhandlerdir/enter_active_mode`


		# Notify someone of what has happened with the original
		# master server and our taking over the monitoring
		# responsibilities.  No one was notified of the master
		# host going down, since the notification would have
		# occurred while we were in standby mode, so this is a good idea...

		#`$echocmd "Master NetSaint host is down!" | /bin/mail -s "Master NetSaint Host Is Down" admin@somedomain.com`
		#`$echocmd "Slave NetSaint host has entered ACTIVE mode and taken over network monitoring responsibilities!" | $mailcmd -s "Slave NetSaint Host Has Entered ACTIVE Mode" admin@somedomain.com`

		;;

	UP)
		# The master host has recovered!
		# We should go back to being the slave host and
		# let the master host do the monitoring, so 
		# enter standby mode...

		`$eventhandlerdir/enter_standby_mode`


		# Notify someone of what has happened.  Users were 
		# already notified of the master host recovery because we
		# were in active mode at the time the recovery happened.
		# However, we should let someone know that we're switching
		# back to standby mode...

		#`$echocmd "The master NetSaint host has recovered, so the slave NetSaint host has returned to standby mode..." | $mailcmd -s "Slave NetSaint Host Has Returned To STANDBY Mode" admin@somedomain.com`

		;;

	esac
	;;

esac
exit 0

