#!/bin/csh -f
#
# $Header: /home/vikas/netmgt/nocol/src/utility/RCS/notifier,v 1.5 1994/06/20 15:19:53 vikas Exp $
#
# program to notify when site is CRITICAL for an extended period of time 
# in NOCOL.
#
#	-vikas@navya.com, May 1994
#
## Tweak these
##
## TOP = "/nocol" ?  TO2 = "trenches@your.domain" ?
set TOP = "<TOP>"
## To send email to a user after site down for x to x+1 hours, set TOx
set TO2 = "<OPSMAIL>"
#set TO3 = "brass@your.domain"
#set TO5 = "hicommand@your.domain"

set PROG = "$TOP/bin/eventselect"
set DATADIR = "$TOP/data"
set MAIL = "/usr/ucb/mail"
set TEMP = "/tmp/notifier.$$"

if ( ! -x ${PROG} ) then
	echo "$0 ERROR: $PROG not found"
#	exit 1
endif

foreach i ( 1 2 3 4 5 6 )
   unset TOMAIL ;

   if ($i == 1 && $?TO1) then
	set TOMAIL = "$TO1"
   else if ($i == 2 && $?TO2) then
	set TOMAIL = "$TO2"
   else if ($i == 3 && $?TO3) then
	set TOMAIL = "$TO3"
   else if ($i == 4 && $?TO4) then 
	set TOMAIL = "$TO4"
   else if ($i == 5 && $?TO5) then
	set TOMAIL = "$TO5"
   else if ($i == 6 && $?TO6) then
	set TOMAIL = "$TO6"
   endif

   if (! $?TOMAIL) continue	# skip

   @ j = $i + 1
   @ T1 = 3600 * $i
   @ T2 = 3600 * $j
   
   ${PROG} -v critical -f +$T2  -t +$T1  ${DATADIR}/* > ${TEMP}

   if ( ! -z ${TEMP} ) then
	cat ${TEMP} | $MAIL -s "Sites down for $i - $j hours" $TOMAIL
   endif

   /bin/rm -f ${TEMP}

end	# of foreach

exit 0
##
