This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
check_cassandra_cluster.sh
153 lines (126 loc) · 2.9 KB
/
check_cassandra_cluster.sh
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
#
# Author : N.Hashimoto
# E-mail : [email protected]
# Description : Verify node joinning cassandra multinode cluster, and
# send alert if the number of live node is less than the specified number.
#
# ------------------------------------------------------------
# functions
# ------------------------------------------------------------
# print help
usage() {
cat << EOF
Usage: $0 -H <host> -P <port> -w <warning> -c <critical>
-H <host> IP address or hostname of the cassandra node to connect, localhost by default.
-P <port> JMX port, 7199 by default.
-w <warning> alert warning state, if the number of live nodes is less than <warning>.
-c <critical> alert critical state, if the number of live nodes is less than <critical>.
-h show command option
-V show command version
EOF
exit 3
}
# Checking the status, outputting the nagios status code
check_status() {
case $retval in
0 )
echo "OK - Live Node:$live_node"
exit 0
;;
1 )
echo "WARNING - Live Node:$live_node"
exit 1
;;
2 )
echo "CRITICAL - Live Node:$live_node"
exit 2
;;
3 )
echo "UNKNOWN - Live Node:$live_node"
exit 3
;;
esac
}
# ------------------------------------------------------------
# variables
# ------------------------------------------------------------
export LANG=C
opt_v=1.00
date=$(date '+%Y%m%d')
host="localhost"
port="7199"
PROGPATH=`dirname $0`
#PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
#REVISION=`echo '$Revision: 1749 $' | sed -e 's/[^0-9.]//g'`
. $PROGPATH/utils.sh
# option definitions
while getopts "c:w:H:P:hV" opt ; do
case $opt in
c )
critical="$OPTARG"
;;
w )
warning="$OPTARG"
;;
H )
host="$OPTARG"
;;
P )
port="$OPTARG"
;;
h )
usage
;;
V )
echo "`basename $0` $opt_v" ; exit 0
;;
* )
usage
;;
esac
done
shift `expr $OPTIND - 1`
# verify warning and critical are number
expr $warning + 1 >/dev/null 2>&1
if [ "$?" -lt 2 ]; then
true
else
echo "-c <critical> $critical must be number."
exit 3
fi
expr $critical + 1 >/dev/null 2>&1
if [ "$?" -lt 2 ]; then
true
else
echo "-c <critical> $critical must be number."
exit 3
fi
# verify warning is less than critical
if [ "$warning" -lt "$critical" ]; then
echo "-w <warning> $warning must not be less than -c <critical> $critical."
exit 3
fi
# ------------------------------------------------------------
# begin script
# ------------------------------------------------------------
# check the number of live node
live_node=$(nodetool -h $host -p $port ring | awk '$3 == "Up" { print $1 }' | sort | uniq | wc -l)
# unless live node is number, reply unknown code
expr $live_node + 1 >/dev/null 2>&1
if [ "$?" -lt 2 ]; then
true
else
retval=3
fi
# verify the number of live node is less than critical, warning
if [ "$live_node" -le "$critical" ]; then
retval=2
else
if [ "$live_node" -le "$warning" ]; then
retval=1
else
retval=0
fi
fi
check_status