#!/bin/ksh

#############################################################################
##
## iMS monitoring and alarm script
##
## This script is part an example framework of what can be done.
## There are MANY ways that you can take this from here.
##
## File: $RCSfile: check_rndtrip,v $
##       A master script for executing a series of test which run with 
##       parameters which change based on the time the test is.
##
## While this package is provided AS-IS and unsupported, we would appreciate
## your comments, feedback and bug-reports at:
##
##      mailtools-feedback @Sign sun.com
##
#############################################################################

_CURR_WDIR=$(dirname $0)

## MAYBE MODIFIED BASED ON SITE SPECIFIC INFORMATION

DELIVER_REPORT=0

while [ $# -gt 0 ]
do
    case "$1" in
	-r)	DELIVER_REPORT=1; break ;;
	-S) 	shift ; report_style="$1";;
    esac
    shift
done

## include definitions if necessary
if [ -z "$HEALTHMON_TMPDIR" ]
then
    . $_CURR_WDIR/../etc/alarms.cfg
fi

SUBJECT="Delivery test results for $domain"

LOGNAME=systest.log
LOGFILE=$reportlogdir/$LOGNAME

if [ $DELIVER_REPORT -eq 1 ]; then

        printf "+----------+-----------+------------+------------+--------+-----------------+\n" >> $LOGFILE
        $_CURR_WDIR/../lib/sendreport -o $sender -s "$SUBJECT" -r $reportrcpts -f $LOGFILE
        $rotatelog -l $LOGNAME
        writeHead $LOGFILE

else

        DMSG=$_CURR_WDIR/../bin/runmonitor
        MINUTE=`date "+%M" | awk '{
	    tens_Units = $1/10
	    split(tens_Units, digits, ".") #create the digits array
	    if (digits[2] < 5 ) {
       	        printf("%1d0", ($1/10))
       	    } else {
       	        printf("%1d5", ($1/10))
       	    }
        }'`

	grep "^$MINUTE DMSG" $_CURR_WDIR/../etc/sequence.cfg | \
	while read input_line
	do
		if [ -z "$input_line" ] ; then
			continue
		fi

		# Format of sequence.cfg is 
		#
		#	05 DMSG -u ims1 -s ssmtp01 -p smux01
		#	15 DMSG -u ims4 -s ssmtp04 -p smux02
		#
		# where -u is the username -s is the smtp host -p is the pop host
		#

		set $input_line
		shift 2
       		. $DMSG -S $report_style $*
	done
fi
## end of script
