Nagios: Check SAP Javastack

Check SAP Javastack with Nagios:

#!/usr/bin/ksh
#
#
#  check_sap_javastack.sh
#  requires sapcontrol from SAP Installation
#
#  written by Silvan Hunkirchen for Computacenter 2009
#  copyright by Computacenter
#  v 0.1 initial Script
#  feature:
#       – check SAP Javastack via sapcontrol
#  v 1.0 debugging
#       – better checking of the status and better parsing of the output of sapcontrol
#       – possibility of excluding services
#
# supported functions :
#   J2EEGetProcessList
#
#
ret=0
# Values needed by script
FUNCTION=$1
SAPCONTROL=$2
USER=$3
PASS=$4
SN=$5
SID=$6
exclude=$7
host=`hostname`
sidadm=`echo $SID`adm
# setting inital variables
status=””
count_exclude=0
case $1 in
J2EEGetProcessList)
# old – bug = awk will overwrite returncode of the application
# result=`su  – $sidadm -c “$SAPCONTROL -user $USER $PASS -format script -host $host -nr $SN -function $FUNCTION | grep -e type -e statetext”| awk ‘{print $3 $4}’`
# get servernames that are configured
result_server=`su  – $sidadm -c “$SAPCONTROL -user $USER $PASS -format script -host $host -nr $SN -function $FUNCTION | grep -e type”| awk ‘{print $3 $4}’`
# get status of each server — could be easier but multidimentional arrays are not possible in ksh
result_status=`su  – $sidadm -c “$SAPCONTROL -user $USER $PASS -format script -host $host -nr $SN -function $FUNCTION | grep -e statetext”| awk ‘{print $3 $4}’`
check_result=`echo $?`
if [ “$check_result” -eq “0” ];then
{
# create all necessary arrays for exclude list, servernames and serverstatus
set -A exclude_list `echo “$exclude”`
count_exclude=${#exclude_list[@]}
set -A server_name `echo “$result_server”|grep -v notset`
count_servers_name=${#server_name[@]}
set -A server_status `echo “$result_status”|grep -v notset`
count_servers_status=${#server_status[@]}
exclude_index=0
if [ “$count_exclude” -gt “0” ];then
# loop through the exclude list and unset all servernames and status if the exclude matches
while [[ “$exclude_index” -lt “$count_exclude” ]]
do
index=0
while [[ “$index” -lt “$count_servers_name” ]]
do
if [ “${server_name[$index]}” == “${exclude_list[$exclude_index]}” ];then
# actual unset the servers not wanted to be checked
unset server_name[$index]
unset server_status[$index]
fi
let “index = index + 1”
done
let “exclude_index = exclude_index + 1”
done
fi
index=0
# loop through the array again to check the serverstatus and create necessary exit codes
while [[ “$index” -lt “$count_servers_name” ]]
do
if [ -n “${server_status[$index]}” ]; then
if [ “${server_status[$index]}” != “Running” ];then
status=${status}” Server ${server_name[$index]} is ${server_status[$index]}<br>”
crit=1
else
status=${status}” ${server_name[$index]}<br>”
fi
fi
let “index = index + 1”
done
}
else
{
echo “Javastack not reachable, probably login problems”
exit 2
}
fi
if [ “$crit” == “1” ];then
echo $status
exit 2
else
echo “All java servers are running<br>”$status
exit 0
fi
;;
*|–help)
echo “check_sap_javastack.sh
currently only supporting to check if SAP javastack processes are up and running
called with
./check_sap_javastack.sh FUNCTION <Place of SAPCONTROL> USER PASS <SN of System> sid <exclude>
ie. ./check_sap_javastack.sh J2EEGetProcessList /usr/sap/SID/JC00/exe/sapcontrol admin secret 00 bwd
or
./check_sap_javastack.sh J2EEGetProcessList /usr/sap/SID/JC00/exe/sapcontrol admin secret 00 bwd “SERVERINSTANCE_1 SERVERINSTANCE_2″
for excluding SERVERINSTANCE_1 and SERVERINSTANCE_2

exit 1
;;
esac

Host Servicedefintion

define service{
use svc_tpl_check_sap_javastack_test
host_name dehq0pid
_OPTION J2EEGetProcessList
_SAPCONTROL /usr/sap/PID/SYS/exe/run/sapcontrol
_USER j2ee_admin
_PASS <passwort>
_SYSNUMBER 00
_SID pid
_IGNORE                 “DebugProxy” <– OPTIONAL
service_description     check Javastack availability
}
Service definition
define service{
name                            svc_tpl_check_sap_javastack_test
use                             svc_tpl_service_test
check_command                   cmd_check_sap_javastack
service_groups                  svc_grp_check_sap_javastack_test
flap_detection_enabled          0
}

Command definition

define command{
command_name    cmd_check_sap_javastack
command_line    /usr/local/nrpe/check_nrpe -H $HOSTADDRESS$ -c check_sap_javastack -a $_SERVICEOPTION$ $_SERVICESAPCONTROL$ $_SERVICEUSER$ $_SERVICEPASS$ $_SERVICESYSNUMBER$ $_SERVICESID$ $_SERVICEIGNORE$
}

Advertisements
This entry was posted in Nagios, SAP and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s