#!/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_ldap,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@sun.com
##
#############################################################################
#  

_CURR_WDIR=$(dirname $0)  # Use built in ksh cmds to find out where am i located

TEST="imta-ldap"

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

NL="
"

TIMESTAMP=`$_CURR_WDIR/../lib/date_util.sh normalize`

# make connection 

LDAP_BASE=`grep -i service.nsmsgdcroot: $LOCAL_CONF_FILE | cut -d" " -f2- `

LDAP_HOST=`grep local.ugldaphost $MSG_CONF_FILE | cut -d"=" -f2- `

$IMMONITOR_ACCESS -L $LDAP_HOST -u $TEST_USER -b "$LDAP_BASE" >> $HEALTHMON_TMPDIR/check_ldap.out.$$ 2>& 1

RESULT=$?

if [ $RESULT -eq 0 ]
then
    COLOR="green"
    _subject="`date` - $TEST OK on $MACHINEDOTS
"
elif  [ $RESULT -eq 64 ]
then
    _subject="`date` - $TEST Not OK on $MACHINEDOTS
"
    COLOR="yellow"
else
    COLOR="red"
    _subject="`date` - $TEST Not OK on $MACHINEDOTS
"
fi

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

print_${report_style}_report

rm -f $HEALTHMON_TMPDIR/check_ldap.out.$$

## end of script
