#!/usr/bin/sh

###############################################################################
#hacmp_monitor.sh
###############################################################################


###############################################################
# This script monitors an PBX resource on a HACMP cluster. 
# This is a basic test to prove that a connection can be established.
# The outline:
#  - check if pbx_exchange server is able to register a server.
#  - If yes, unregister the dummy server.
###############################################################

#DC: Remove the logs
LOG_FILE="/var/tmp/hacmp_pbx_monitor.log" 
echo "HACMP MONITOR\n" >> $LOG_FILE 
date >> $LOG_FILE
port_number=1556;
dir="/opt/VRTSpbx/bin";
if [ $^O=~/aix/i ]; then
   #$ENV{'LIBPATH'}=$dir;
   #$ENV{'LIBPATH'}.=":/opt/VRTSicsco/lib";
   #$ENV{'LIBPATH'}.=":/opt/VRTSpbx/lib";
   libpath="$dir:/opt/VRTSpbx/lib";
   export LIBPATH="$LIBPATH:$libpath";
   command_string="/opt/VRTSpbx/bin/cluster/monitor_server localhost $port_number pbx_monitor";
else
   echo "PBX:monitor This is not a AIX machine\n"
   exit 1;
fi
echo "PBX:monitor called\n"
$command_string
retcode=$?

if [ $retcode == 0 ]; then
    echo "PBX:monitor : PBX is running\n"
    echo "PBX:monitor : PBX is running\n" >> $LOG_FILE
    exit 0;
else
    echo "PBX:monitor : PBX is not running !\n";
    echo "PBX:monitor : PBX is not running !\n">> $LOG_FILE
    exit 1;
fi

