#!/bin/sh
PATH=/opt/csw/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
LD_LIBARARY_PATH=/opt/csw/lib:/usr/sfw/lib:/usr/local/ssl/lib

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="1.4.15"

. $PROGPATH/utils.sh


print_usage() {
        echo "Usage: $PROGNAME hostname,ip ssl,nossl application"
}

print_help() {
        print_revision $PROGNAME $REVISION
        echo ""
        print_usage
        echo ""
        echo "This plugin checks hardware status using the lm_sensors package."
        echo ""
        support
        exit 0
}
if [ $# -lt 2 ]
then
	print_usage
	exit 0
fi
case "$1" in
        --help)
                print_help
                exit 0
                ;;
        -h)
                print_help
                exit 0
                ;;
        --version)
        print_revision $PROGNAME $REVISION
                exit 0
                ;;
        -V)
                print_revision $PROGNAME $REVISION
                exit 0
                ;;
        *)
 		host=$1
		ssl=$2
		app=$3
		serverid=`echo $host | cut -c15`
		#echo Checking $1 with $2
		case $2 in 
		ssl)
	        	status=`/opt/csw/bin/curl -IqsLLk https://${host}:14100/oam/server/logout | grep -c "200 OK"`	
		;;
		nossl)
	        	status=`/opt/csw/bin/curl -IqsLLk http://${host}:14100/oam/server/logout | grep -c "200 OK"`	
		;;
		esac
                if [ $status -eq 1 ] 
			then
                        nagiosstat=Ok 
			echo "$host OAM status OK"
			conn=`ssh -qT $host netstat -an | grep 5575 | awk '{print $2}' | wc -l`
                        echo "OAM Connections: $conn"
			exit 0
		else
                        nagiosstat=Down 
			echo "$host OAM status Down"	
			ssh wassrv@$host tail -100 /data/Oracle/Middleware/user_projects/domains/IAMDomain/servers/oam_server${serverid}/logs/oam_server{$serverid}.log
			conn=`ssh -qT $host netstat -an | grep 5575 | awk '{print $2}' | wc -l`
                        echo "OAM Connections: $conn"
			#/usr/local/nagios/libexec/eventhandlers/kill_oam
			exit 2
                fi
                ;;
esac

