#!/bin/bash # # Copyright (c) 2013-2024 Linagora # # This program/library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 2.1 of the License, or (at your # option) any later version. # # This program/library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program/library; If not, see http://www.gnu.org/licenses/ # for the GNU Lesser General Public License version 2.1. # ################################################################################ # # Christophe DENEUX - Linagora # ################################################################################ # # This Nagios plugin was created to check Petals BC SOAP status # ################################################################################ PROGNAME=`basename $0` PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` . $PROGPATH/utils.sh print_usage() { echo "Usage:" echo " $PROGNAME -h -n -u -p -n --http-thread-pool-current-allocated-threads -w -c " echo " $PROGNAME -h -n -u -p -n --http-thread-pool-current-enqueued-requests" echo " $PROGNAME --help" } print_help() { echo "" print_usage echo "" echo "Check Petals BC SOAP status" echo "" echo "-h " echo " The Petals container hostanme where the Petals BC SOAP is running. Default value: localhost" echo "-n " echo " The JMX port of the Petals ESB container: Default value: 7700" echo "-u " echo " The JMX user with which the connecion must be done. Default value: petals" echo "-p " echo " The password of the JMX user with which the connection must be done. Default value: petals" echo "-i " echo " The unique identifier of the Petals BC SOAP on the Petals ESB container. Default value: petals-bc-soap" echo "-w " echo " The warning threshold" echo "-c " echo " The critical threshold" echo "--http-thread-pool-current-allocated-threads" echo " Check the current number of allocated threads of the HTTP thread pool" echo "--outgoing-ws-clients -o " echo " Check the Web-Service client pool of the operation " echo "--mex_current_acceptor_threads" echo " Check the current number of message exchange acceptor thread pool" echo "--mex_current_processor_objects" echo " Check the current number of message exchange processor objects" echo "--mex_current_processor_threads" echo " Check the current number of message exchange processor threads" echo "--help" echo " Print this help screen" echo "" } HOSTNAME="localhost" JMXPORT="7700" JMXUSER="petals" JMXPWD="petals" BCSOAPID="petals-bc-soap" while (( "$#" )); do case $1 in -h) if [ ! -z "$2" ]; then HOSTNAME=$2 shift 2 else echo "Hostname is missing" exit $STATE_UNKNOWN fi ;; -n) if [ ! -z "$2" ]; then JMXPORT=$2 shift 2 else echo "JMX Port is missing" exit $STATE_UNKNOWN fi ;; -u) if [ ! -z "$2" ]; then JMXUSER=$2 shift 2 else echo "JMX User is missing" exit $STATE_UNKNOWN fi ;; -p) if [ ! -z "$2" ]; then JMXPWD=$2 shift 2 else echo "JMX Password is missing" exit $STATE_UNKNOWN fi ;; -i) if [ ! -z "$2" ]; then BCSOAPID=$2 shift 2 else echo "Petals BC SOAP is missing" exit $STATE_UNKNOWN fi ;; -w) if [ ! -z "$2" ]; then warn_threshold=$2 shift 2 else echo "Warning threshold is missing" exit $STATE_UNKNOWN fi ;; -c) if [ ! -z "$2" ]; then critical_threshold=$2 shift 2 else echo "Critical threshold is missing" exit $STATE_UNKNOWN fi ;; -o) if [ ! -z "$2" ]; then OPERATION=$2 shift 2 else echo "Operation is missing" exit $STATE_UNKNOWN fi ;; --help) print_help exit $STATE_OK ;; --http-thread-pool-current-allocated-threads) cmd=$1 shift ;; --outgoing_ws_clients) cmd=$1 shift ;; --mex_current_acceptor_threads) cmd=$1 shift ;; --mex_current_processor_objects) cmd=$1 shift ;; --mex_current_processor_threads) cmd=$1 shift ;; *) echo "Unknown argument: $1" print_usage exit $STATE_UNKNOWN esac done if [ -z "$warn_threshold" ]; then echo "Warning threshold is missing" exit $STATE_UNKNOWN fi if [ -z "$critical_threshold" ]; then echo "Critical threshold is missing" exit $STATE_UNKNOWN fi # Information options case "$cmd" in --http-thread-pool-current-allocated-threads) httpthreadpoolstats=`petals-cli -h $HOSTNAME -n $JMXPORT -u $JMXUSER -p $JMXPWD -c -- monitoring -o petals-bc-soap -f http-thread-pool -- -n $BCSOAPID 2>&1` res=`echo $?` if [ $res -eq 0 ]; then currentallocatedthreads=`echo $httpthreadpoolstats | tr ' ' '\n' | grep AllocatedThreadsCurrent | cut -d ":" -f 2` if [ $currentallocatedthreads -ge $warn_threshold ]; then echo "WARN - Current allocated threads: $currentallocatedthreads" exit $STATE_WARNING elif [ $currentallocatedthreads -ge $critical_threshold ]; then echo "CRITICAL - Current allocated threads: $currentallocatedthreads" exit $STATE_CRITICAL else echo "OK - Current allocated threads: $currentallocatedthreads" exit $STATE_OK fi else echo $httpthreadpoolstats exit $STATE_UNKNOWN fi ;; --mex_current_acceptor_threads) mexacceptorpoolstats=`petals-cli -h $HOSTNAME -n $JMXPORT -u $JMXUSER -p $JMXPWD -c -- monitoring -o generic -f mex-acceptor-thread-pool -- -n $BCSOAPID 2>&1` res=`echo $?` if [ $res -eq 0 ]; then currentacceptors=`echo $mexacceptorpoolstats | tr ' ' '\n' | grep AllocatedThreadsCurrent | cut -d ":" -f 2` if [ $currentacceptors -le $critical_threshold ]; then echo "CRITICAL - Current MEX Acceptor threads: $currentacceptors" exit $STATE_CRITICAL elif [ $currentacceptors -le $warn_threshold ]; then echo "WARN - Current MEX Acceptor threads: $currentacceptors" exit $STATE_WARNING else echo "OK - Current MEX Acceptor threads: $currentacceptors" exit $STATE_OK fi else echo $mexacceptorpoolstats exit $STATE_UNKNOWN fi ;; --mex_current_processor_objects) mexprocessorobjectstats=`petals-cli -h $HOSTNAME -n $JMXPORT -u $JMXUSER -p $JMXPWD -c -- monitoring -o generic -f mex-processor-object-pool -- -n $BCSOAPID 2>&1` res=`echo $?` if [ $res -eq 0 ]; then currentprocessors=`echo $mexprocessorobjectstats | tr ' ' '\n' | grep BorrowedObjectsCurrent | cut -d ":" -f 2` if [ $currentprocessors -ge $warn_threshold ]; then echo "WARN - Current MEX Processor objects: $currentprocessors" exit $STATE_WARNING elif [ $currentprocessors -ge $critical_threshold ]; then echo "CRITICAL - Current MEX Processor objects: $currentprocessors" exit $STATE_CRITICAL else echo "OK - Current MEX Processor objects: $currentprocessors" exit $STATE_OK fi else echo $mexprocessorobjectstats exit $STATE_UNKNOWN fi ;; --mex_current_processor_threads) mexprocessorthreadstats=`petals-cli -h $HOSTNAME -n $JMXPORT -u $JMXUSER -p $JMXPWD -c -- monitoring -o generic -f mex-processor-thread-pool -- -n $BCSOAPID 2>&1` res=`echo $?` if [ $res -eq 0 ]; then currentprocessors=`echo $mexprocessorthreadstats | tr ' ' '\n' | grep AllocatedThreadsCurrent | cut -d ":" -f 2` if [ $currentprocessors -ge $warn_threshold ]; then echo "WARN - Current MEX Processor threads: $currentprocessors" exit $STATE_WARNING elif [ $currentprocessors -ge $critical_threshold ]; then echo "CRITICAL - Current MEX Processor threads: $currentprocessors" exit $STATE_CRITICAL else echo "OK - Current MEX Processor threads: $currentprocessors" exit $STATE_OK fi else echo $mexprocessorthreadstats exit $STATE_UNKNOWN fi ;; --outgoing_ws_clients) outwsclientstats=`petals-cli -h $HOSTNAME -n $JMXPORT -u $JMXUSER -p $JMXPWD -c -- monitoring -o petals-bc-soap -f ws-clients-pools -- -n $BCSOAPID --query-operations INUSE_CUR $OPERATION 2>&1` res=`echo $?` if [ $res -eq 0 ]; then currentwsclients=`echo $outwsclientstats | cut -d "!" -f 2` if [ $currentwsclients -ge $warn_threshold ]; then echo "WARN - Current Web-Service clients: $currentwsclients" exit $STATE_WARNING elif [ $currentwsclients -ge $critical_threshold ]; then echo "CRITICAL - Current Web-Service clients: $currentwsclients" exit $STATE_CRITICAL else echo "OK - Current Web-Service clients: $currentwsclients" exit $STATE_OK fi else echo $outwsclientstats exit $STATE_UNKNOWN fi ;; *) print_usage exit $STATE_UNKNOWN esac