Zionetrix::Git
Repositories
Help
Report an Issue
check_heartbeat
Code
Commits
Branches
Tags
Search
Tree:
d7cc82c
Branches
Tags
master
check_heartbeat
check_heartbeat
Initial commit
Benjamin Renard
commited
d7cc82c
at 2011-10-26 16:19:19
check_heartbeat
Blame
History
Raw
#!/bin/bash # Author: Benjamin Renard # Date: 2011-10-26 # Description: Nagios check plugin to test Linux HA cluster # status using cl_status # Get program path REVISION=1.0 PROGNAME=`/usr/bin/basename $0` PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'` NODE_NAME=`uname -n` CL_ST='/usr/bin/cl_status' WARNING_NUMBER_PING_NODE=1 if [ -f $PROGPATH/utils.sh ] then .$PROGPATH/utils.sh elif [ -f /usr/lib/nagios/plugins/utils.sh ] then . /usr/lib/nagios/plugins/utils.sh else echo "Can't find utils.sh" exit 3 fi function usage { echo "Nagios plugin to test heartbeat status using cl_status Usage: $0 [-h|--help] [-v|--version] --help -h Print this help information --version -v Print version of plugin " } case "$1" in --help | -h) print_revision $PROGNAME $REVISION echo usage echo support exit $STATE_OK ;; --version | -v) print_revision $PROGNAME $REVISION exit $STATE_OK ;; esac $CL_ST hbstatus > /dev/null res=$? if [ $res -ne 0 ] then echo "CRITICAL: Heartbeat is not running on this node" exit $CRITICAL fi NODES=`$CL_ST listnodes` PERF_DATA="" NODE_COUNT=0 NODE_ACTIVE=0 PING_COUNT=0 PING_ACTIVE=0 LINK_DOWN=0 for node in $NODES do if [ "$node" == "$NODE_NAME" ] then let NODE_COUNT=NODE_COUNT+1 let NODE_ACTIVE=NODE_ACTIVE+1 continue fi type=$( $CL_ST nodetype $node ) status=`$CL_ST nodestatus $node` res=$? case "$type" in normal) link=0 link_up=0 let NODE_COUNT=NODE_COUNT+1 if [ "$status" == "active" ] then let NODE_ACTIVE=NODE_ACTIVE+1 fi for link in $( $CL_ST listhblinks $node ) do let link_count=link_count+1 status=$( $CL_ST hblinkstatus $node $link ) if [ "$status" == "up" ] then let link_up=link_up+1 else let LINK_DOWN=LINK_DOWN+1 fi done let warn=link_count-1 PERF_DATA="$PERF_DATA linkup_$node:$link_up;$warn;0;0;$link_count" ;; ping) let PING_COUNT=PING_COUNT+1 if [ "$status" == "ping" ] then let PING_ACTIVE=PING_ACTIVE+1 fi ;; esac done PERF_DATA="$PERF_DATA ping_active:$PING_ACTIVE;$WARNING_NUMBER_PING_NODE;0;0;$PING_COUNT" let warn=NODE_COUNT-1 PERF_DATA="$PERF_DATA node_active:$NODE_ACTIVE;$warn;0;0;$NODE_COUNT" msg="$NODE_ACTIVE/$NODE_COUNT heartbeat node(s) active(s)" if [ $NODE_ACTIVE -eq 0 ] then echo "CRITICAL : $msg |$PERF_DATA" exit $STATE_CRITICAL elif [ $NODE_ACTIVE -ne $NODE_COUNT ] then echo "WARNING : $msg |$PERF_DATA" exit $STATE_WARNING elif [ $LINK_DOWN -ne 0 ] then echo "WARNING : $msg but all link are not up |$PERF_DATA" exit $STATE_WARNING elif [ $PING_ACTIVE -le $WARNING_NUMBER_PING_NODE ] then echo "WARNING : $msg but only $PING_ACTIVE ping node(s) up |$PERF_DATA" exit $STATE_WARNING else echo "OK : $msg |$PERF_DATA" exit $STATE_OK fi