#!/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_mconn,v $
##
##   (Big Brother external plugin) 
##       A script which tests a full interaction with the SMTP port
##	 rather than just seeing if the port responds
##
## 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)

Usage () {
    echo "$0\t "
    echo "\t [-S foo <use reporting style foo for alarms> ]"
    exit 
}

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

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

TEST=imta-mconn

echo "" > $HEALTHMON_TMPDIR/check_mconn.out.$$

# make connection 
$IMMONITOR_ACCESS -f $sender -u nobody@bitbucket -S \
     $MACHINEDOTS >> $HEALTHMON_TMPDIR/check_mconn.out.$$ 2>& 1

if [ $? = 0 ]
then
    COLOR="green"
    _subject="`date` - $TEST on $MACHINEDOTS 0K"
else
    COLOR="red"
    _subject="`date` - $TEST on $MACHINEDOTS DOWN"
fi

_full_report="`cat $HEALTHMON_TMPDIR/check_mconn.out.$$`"

print_${report_style}_report

rm -f $HEALTHMON_TMPDIR/check_mconn.out.*

## end of script
