forked from inuits/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_zookeeper
executable file
·129 lines (116 loc) · 2.72 KB
/
check_zookeeper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#
# Author: Bart Janssens
# Email: [email protected]
# Date: Wed Jun 10 2016
#
# Requires the nmap-ncat and bc packages to work
#
showhelp () {
cat <<eof
Check to monitor the zookeeper instance. Checks if it is reachable,
if it's reporting 'imok' and if the amount of connections isn't above the given values.
Parameters:
--host|-h : The host to try and connect to, defaults to localhost.
--port|-p : The port to try and connect to, default to 2181.
--warning|-w : The warning threashold, defaults to 250.
--critical|-c : The critical threashold, defaults to 300.
Example usage:
./check_zookeeper --host localhost --port 2181 --warning 250 --critical 300
eof
exit 3
}
params () {
if [ -z $host ]; then host='localhost'; fi
if [ -z $port ]; then port='2181'; fi
if [ -z $connections_warning ]; then connections_warning='250'; fi
if [ -z $connections_critical ]; then connections_critical='300'; fi
}
check_reachable () {
echo 'ruok' | nc $host $port 1>/dev/null && nc_status=$?
if [ ! $nc_status -eq '0' ]
then
message="Unknown: Unable to complete nc command"
exitstatus=3
quit
fi
}
check_alive () {
status=$( echo ruok | nc $host $port )
if [ ! $status == 'imok' ]
then
message="Critical: Zookeeper reporting status: $status"
exitstatus=2
quit
fi
}
get_srvr () {
srvr=$( echo srvr | nc $host $port )
}
check_connections () {
current_connections=$( echo "$srvr" | grep -i connections | cut -d ' ' -f 2 )
if [ ! -z $current_connections ]
then
if (( ${current_connections} < ${connections_critical} ))
then
if (( ${current_connections} < ${connections_warning} ))
then
message="Ok: Amount of connections is currently: $current_connections"
exitstatus=0
quit
else
message="Warning: Amount of connections is currently: $current_connections"
exitstatus=1
quit
fi
else
message="Critical: Amount of connections is currently: $current_connections"
exitstatus=2
quit
fi
else
message="Warning: Zookeeper reporting status: $status, but failed to get the connections"
exitstatus=1
quit
fi
}
quit () {
echo "$message" && exit $exitstatus
}
# start the case-ing
while test -n "$1"
do
case "$1" in
--help|-h)
showhelp
;;
--port|-p)
shift
port=$1
shift
;;
--host|-h)
shift
host=$1
shift
;;
--warning|-w)
shift
connections_warning=$1
shift
;;
--critical|-c)
shift
connections_critical=$1
shift
;;
*)
showhelp
;;
esac
done
params
check_reachable
check_alive
get_srvr
check_connections