#! /usr/bin/ksh # # check_weblogic_sessions # nagios plugin to check if a WebAppComponentRuntime object on a weblogic application server is exceeding a maximum specified # concurrent sessions value # author: Sergei Haramundanis 08-Nov-2006 # update: [2.0] 12-Apr-2007 by S. Haramundanis to include performing monitor within a specific timeframe # update: [2.1] 20-Jun-2007 by S. Haramundanis to include port # in .dat filename to support monitoring multiple weblogic instances # # usage: check_weblogic_sessions runtime_directory url userid password object_name maximum_concurrent_sessions check_from_time check_to_time # # Description: # # This plugin will check the concurrent sessions of a WebAppComponentRuntime object with the object_name specified running on a # weblogic application server via the weblogic.Admin client, # at a specific timeframe specified by check_from_time and check_to_time (in HHMM format) # # This plugin requires access to weblogic.jar to access the weblogic.Admin client # (see definition of WEBLOGIC_LIB further on in this script, you may need to change it) # # This plugin also creates a check_weblogic_sessions_port.dat file in the runtime_directory specified which contains the snapshot output of all # WebAppComponentRuntime MBean metrics for the weblogic application server at the url specified. The plugin parses this file to extract # the OpenSessionsCurrentCount of the WebAppComponentRuntime MBean which matches the object_name specified in the ObjectName record # # Output: # # During any run of the plugin, the value returned will be as follows: # # if the current time is outside the specified timeframe it will return an OK state with the message: # # [OK] current time outside of monitoring timeframe check_from_time and check_to_time # # if the current time is within the specified timeframe: # # it will poll all WebAppComponentRuntime MBeans on the weblogic application server at the url specified, # writing the output to check_weblogic_sessions_port.dat and will parse the .dat file for the OpenSessionsCurrentCount of the WebAppComponentRuntime # MBean with the ObjectName which matches the pattern in the object_name specified # # here is an example of an ObjectName of a weblogic WebAppComponentRuntime object which would be used to match the object_name specified: # # ObjectName: weblogic-nd-admin_weblogic-nd-admin_clareon_clareon # # Once the plugin finds the correct WebAppComponentRuntime MBean and parses its OpenSessionsCurrentCount it will make the following check: # # 1. check the OpenSessionsCurrentCount to determine if it is greater than the maximum_concurrent_sessions specified # # if the OpenSessionsCurrentCount is less than or equal to the maximum_concurrent_sessions specified it will return an OK state with a # message similar to the following example: # # [OK] 123 concurrent sessions less than or equal to maximum concurrent sessions of 400 # # if the OpenSessionsCurrentCount is greater than the maximum_concurrent_sessions specified it will return a CRITICAL state with # a message similar to the following example: # # [CRITICAL] 438 concurrent sessions greater than maximum concurrent sessions of 400 # SCRIPTPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'` . ${SCRIPTPATH}/utils.sh # sets correct STATE_* return values if [ "${1}" = "" -o "${1}" = "--help" ]; then echo "check_weblogic_sessions 2.1" echo "" echo "nagios plugin to check if a WebAppComponentRuntime object on a weblogic application server is exceeding a maximum specified" echo "concurrent sessions value" echo "" echo "This nagios plugin comes with ABSOLUTELY NO WARRANTY." echo "You may redistribute copies of this plugin under the terms of the GNU General Public License" echo "as long as the original author, edit history and description information remain in place." echo "" echo "usage: check_weblogic_sessions runtime_directory url userid password object_name maximum_concurrent_sessions check_from_time check_to_time" echo "usage: check_weblogic_sessions --help" echo "usage: check_weblogic_sessions --version" exit ${STATE_OK} fi if [ ${1} == "--version" ]; then echo "check_weblogic_sessions 2.1" echo "This nagios plugin comes with ABSOLUTELY NO WARRANTY." echo "You may redistribute copies of this plugin under the terms of the GNU General Public License" echo "as long as the original author, edit history and description information remain in place." exit ${STATE_OK} fi if [ $# -lt 8 ]; then echo "[CRITICAL] insufficient arguments" exit ${STATE_CRITICAL} fi RUNDIR=${1} URL=${2} USERID=${3} PASSWORD=${4} OBJECT_NAME=${5} MAXIMUM_CONCURRENT_SESSIONS=${6} CHECK_FROM_TIME=${7} CHECK_TO_TIME=${8} #echo "RUNDIR=\"${RUNDIR}\"" #echo "URL=\"${URL}\"" #echo "USERID=\"${USERID}\"" #echo "PASSWORD=\"${PASSWORD}\"" #echo "OBJECT_NAME=\"${OBJECT_NAME}\"" #echo "MAXIMUM_CONCURRENT_SESSIONS=\"${MAXIMUM_CONCURRENT_SESSIONS}\"" #echo "CHECK_FROM_TIME=\"${CHECK_FROM_TIME}\"" #echo "CHECK_TO_TIME=\"${CHECK_TO_TIME}\"" START_TIME=`date +%H%M%S` # check to make sure runtime directory exists if [ ! -d ${RUNDIR} ]; then echo "[CRITICAL] runtime directory \"${RUNDIR}\" does not exist" exit ${STATE_CRITICAL} fi # check to make sure runtime directory is writeable if [ ! -w ${RUNDIR} ]; then echo "[CRITICAL] runtime directory \"${RUNDIR}\" is not writeable by this process" exit ${STATE_CRITICAL} fi let index=`echo $URL ":" | awk '{print(index($1,$2))}'` #### if [ ${index} -eq 0 ]; then echo "[CRITICAL] URL does not include port (e.g. host:port)" exit ${STATE_CRITICAL} fi #### let index=index+1; URL_PORT=`echo $URL $index | awk '{print(substr($1,$2))}'` #echo "URL_PORT=\"${URL_PORT}\"" #### if [ "${URL_PORT}" == "" ]; then echo "[CRITICAL] URL does not include port (e.g. host:port)" exit ${STATE_CRITICAL} fi #### # if .dat file exists, check to make sure file can be written to if [ -f ${RUNDIR}/check_weblogic_sessions_${URL_PORT}.dat -a ! -w ${RUNDIR}/check_weblogic_sessions_${URL_PORT}.dat ]; then echo "[CRITICAL] \"${RUNDIR}/check_weblogic_sessions_${URL_PORT}.dat\" is not writeable by this process" exit ${STATE_CRITICAL} fi export WEBLOGIC_LIB=/usr/local/weblogic813/server/lib # retrieve current date and time CURRENT_DATE=`date +%Y%m%d` CURRENT_TIME=`date +%H%M` CURRENT_DATETIME=`date +%Y%m%d%H%M` CHECK_FROM_DATETIME=`echo ${CURRENT_DATE}${CHECK_FROM_TIME}` CHECK_TO_DATETIME=`echo ${CURRENT_DATE}${CHECK_TO_TIME}` #echo "CURRENT_DATE=\"${CURRENT_DATE}\"" #echo "CURRENT_TIME=\"${CURRENT_TIME}\"" #echo "CURRENT_DATETIME=\"${CURRENT_DATETIME}\"" #echo "CHECK_FROM_DATETIME=\"${CHECK_FROM_DATETIME}\"" #echo "CHECK_TO_DATETIME=\"${CHECK_TO_DATETIME}\"" if [ ${CURRENT_DATETIME} -ge ${CHECK_FROM_DATETIME} -a ${CURRENT_DATETIME} -le ${CHECK_TO_DATETIME} ] ; then let maximum_concurrent_sessions=${MAXIMUM_CONCURRENT_SESSIONS} java -cp ${WEBLOGIC_LIB}/weblogic.jar weblogic.Admin -url ${URL} -username ${USERID} -password ${PASSWORD} GET -pretty -type WebAppComponentRuntime > ${RUNDIR}/check_weblogic_sessions_${URL_PORT}.dat 2>&1 RETURN_VALUE=$? #echo "RETURN_VALUE=\"${RETURN_VALUE}\"" if [ ${RETURN_VALUE} -ne 0 ]; then WEBAPPCR_DATA=`cat ${RUNDIR}/check_weblogic_sessions_${URL_PORT}.dat 2>&1` WEBAPPCR_DATA=`echo ${WEBAPPCR_DATA} | sed /^$/d` # remove newlines echo "[CRITICAL] unable to access WebAppComponentRuntime object: ${WEBAPPCR_DATA}" exit ${STATE_CRITICAL} fi # read .dat file until ObjectName: object_name is found OBJECT_NAME_FOUND="F" { while read record ; do if [ "${OBJECT_NAME_FOUND}" = "F" ]; then #echo "record=\"${record}\"" let objectname_index=`echo ${record} | awk '{ print index($0,objectname) }' objectname=ObjectName 2>&1` #echo "objectname_index=\"${objectname_index}\"" if [ ${objectname_index} -gt 0 ]; then #echo "record=\"${record}\"" OBJECTNAME_VALUE=`echo ${record} | awk '{ print ($2) }'` #echo "OBJECTNAME_VALUE=\"${OBJECTNAME_VALUE}\"" if [ "${OBJECTNAME_VALUE}" = "${OBJECT_NAME}" ]; then OBJECT_NAME_FOUND="T" read record #echo "OBJECT_NAME_FOUND=\"${OBJECT_NAME_FOUND}\"" #echo "record=\"${record}\"" let opensessionscurrentcount=`echo ${record} | awk '{ print ($2) }'` #echo "opensessionscurrentcount=\"${opensessionscurrentcount}\"" if [ ${opensessionscurrentcount} -gt ${maximum_concurrent_sessions} ]; then END_TIME=`date +%H%M%S` let ELAPSED_TIME=${END_TIME}-${START_TIME} echo "[CRITICAL] ${opensessionscurrentcount} concurrent sessions greater than maximum concurrent sessions of ${maximum_concurrent_sessions} | elapsedTime=${ELAPSED_TIME}secs" exit ${STATE_CRITICAL} else END_TIME=`date +%H%M%S` let ELAPSED_TIME=${END_TIME}-${START_TIME} echo "[OK] ${opensessionscurrentcount} concurrent sessions less than or equal to maximum concurrent sessions of ${maximum_concurrent_sessions} | elapsedTime=${ELAPSED_TIME}secs" exit ${STATE_OK} fi fi fi fi done } < ${RUNDIR}/check_weblogic_sessions_${URL_PORT}.dat if [ "${OBJECT_NAME_FOUND}" = "F" ]; then END_TIME=`date +%H%M%S` let ELAPSED_TIME=${END_TIME}-${START_TIME} echo "[CRITICAL] unable to find WebAppComponentRuntime object with ObjectName \"${OBJECT_NAME}\" | elapsedTime=${ELAPSED_TIME}secs" exit ${STATE_CRITICAL} fi else END_TIME=`date +%H%M%S` let ELAPSED_TIME=${END_TIME}-${START_TIME} echo "[OK] current time outside of monitoring timeframe ${CHECK_FROM_TIME} and ${CHECK_TO_TIME} | elapsedTimeSecs=${ELAPSED_TIME}" exit ${STATE_OK} fi # shouldn't get here, but if we do return CRITICAL with reason unknown END_TIME=`date +%H%M%S` let ELAPSED_TIME=${END_TIME}-${START_TIME} echo "[CRITICAL] exiting with reason unknown, check shell script execution | elapsedTime=${ELAPSED_TIME}secs" exit ${STATE_CRITICAL}