Initial commit
Benjamin Renard

Benjamin Renard commited on 2011-10-26 16:19:19
Showing 1 changed files, with 138 additions and 0 deletions.

... ...
@@ -0,0 +1,138 @@
1
+#!/bin/bash
2
+# Author: Benjamin Renard
3
+# Date: 2011-10-26
4
+# Description: Nagios check plugin to test Linux HA cluster
5
+#              status using cl_status
6
+
7
+# Get program path
8
+REVISION=1.0
9
+PROGNAME=`/usr/bin/basename $0`
10
+PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
11
+
12
+NODE_NAME=`uname -n`
13
+CL_ST='/usr/bin/cl_status'
14
+
15
+WARNING_NUMBER_PING_NODE=1
16
+
17
+if  [ -f $PROGPATH/utils.sh ]
18
+then
19
+	.$PROGPATH/utils.sh
20
+elif [ -f /usr/lib/nagios/plugins/utils.sh ]
21
+then
22
+	. /usr/lib/nagios/plugins/utils.sh
23
+else
24
+	echo "Can't find utils.sh"
25
+	exit 3
26
+fi
27
+
28
+function usage {
29
+    echo "Nagios plugin to test heartbeat status using cl_status
30
+
31
+Usage: $0 [-h|--help] [-v|--version]
32
+  --help -h	Print this help information
33
+  --version -v  Print version of plugin
34
+"
35
+}
36
+
37
+case "$1" in
38
+	--help | -h)
39
+		print_revision $PROGNAME $REVISION
40
+		echo
41
+		usage
42
+		echo
43
+		support
44
+		exit $STATE_OK
45
+	;;
46
+	--version | -v)
47
+		print_revision $PROGNAME $REVISION
48
+		exit $STATE_OK
49
+	;;
50
+esac
51
+
52
+$CL_ST hbstatus > /dev/null
53
+res=$?
54
+if [ $res -ne 0 ]
55
+then
56
+  echo "CRITICAL: Heartbeat is not running on this node"
57
+  exit $CRITICAL
58
+fi
59
+
60
+NODES=`$CL_ST listnodes`
61
+
62
+PERF_DATA=""
63
+
64
+NODE_COUNT=0
65
+NODE_ACTIVE=0
66
+PING_COUNT=0
67
+PING_ACTIVE=0
68
+LINK_DOWN=0
69
+for node in $NODES
70
+do
71
+	if [ "$node" == "$NODE_NAME" ]
72
+	then
73
+		let NODE_COUNT=NODE_COUNT+1
74
+		let NODE_ACTIVE=NODE_ACTIVE+1
75
+		continue
76
+	fi
77
+	type=$( $CL_ST nodetype $node )
78
+	status=`$CL_ST nodestatus $node`
79
+	res=$?
80
+	case "$type" in
81
+		normal)
82
+			link=0
83
+			link_up=0
84
+			let NODE_COUNT=NODE_COUNT+1
85
+			if [ "$status" == "active" ]
86
+			then
87
+				let NODE_ACTIVE=NODE_ACTIVE+1
88
+			fi
89
+			for link in $( $CL_ST listhblinks $node )
90
+			do
91
+				let link_count=link_count+1
92
+				status=$( $CL_ST hblinkstatus $node $link )
93
+				if [ "$status" == "up" ]
94
+				then
95
+					let link_up=link_up+1
96
+				else
97
+					let LINK_DOWN=LINK_DOWN+1
98
+				fi
99
+			done
100
+			let warn=link_count-1
101
+			PERF_DATA="$PERF_DATA linkup_$node:$link_up;$warn;0;0;$link_count"
102
+		;;
103
+		ping)
104
+			let PING_COUNT=PING_COUNT+1
105
+			if [ "$status" == "ping" ]
106
+			then
107
+				let PING_ACTIVE=PING_ACTIVE+1
108
+			fi	
109
+		;;
110
+	esac
111
+done
112
+
113
+PERF_DATA="$PERF_DATA ping_active:$PING_ACTIVE;$WARNING_NUMBER_PING_NODE;0;0;$PING_COUNT"
114
+
115
+let warn=NODE_COUNT-1
116
+PERF_DATA="$PERF_DATA node_active:$NODE_ACTIVE;$warn;0;0;$NODE_COUNT"
117
+
118
+msg="$NODE_ACTIVE/$NODE_COUNT heartbeat node(s) active(s)"
119
+if [ $NODE_ACTIVE -eq 0 ]
120
+then
121
+	echo "CRITICAL : $msg |$PERF_DATA"
122
+	exit $STATE_CRITICAL
123
+elif [ $NODE_ACTIVE -ne $NODE_COUNT ]
124
+then
125
+	echo "WARNING : $msg |$PERF_DATA"
126
+	exit $STATE_WARNING
127
+elif [ $LINK_DOWN -ne 0 ]
128
+then
129
+	echo "WARNING : $msg but all link are not up |$PERF_DATA"
130
+	exit $STATE_WARNING
131
+elif [ $PING_ACTIVE -le $WARNING_NUMBER_PING_NODE ]
132
+then
133
+	echo "WARNING : $msg but only $PING_ACTIVE ping node(s) up |$PERF_DATA"
134
+	exit $STATE_WARNING
135
+else
136
+	echo "OK : $msg |$PERF_DATA"
137
+	exit $STATE_OK
138
+fi
0 139