-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-galera.sh
45 lines (36 loc) · 1.1 KB
/
check-galera.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
#!/bin/bash
#
# Very simple Galera cluster status checker. It gets the readiness status and cluster size output from galera-status and makes a simple decision.
# ready != "ON" -> CRIT
# cluster_size == $1 -> OK
# cluster_size > $1/2 -> WARN
# cluster_size <= $1/2 -> CRIT
number='^[0-9]+$'
if ! [[ $1 =~ $number ]]; then
echo "Improper usage: Send expected cluster size as \$1. Must be numeric."
exit 3
fi
ready=`galera-status --batch |grep wsrep_ready|awk '{print $2}'`
cluster_size=`galera-status --batch |grep wsrep_cluster_size|awk '{print $2}'`
if [ $cluster_size -gt $1 ]; then
echo "Cluster size is larger than expected... WTF?"
exit 3
fi
if [ "$ready" != "ON" ]; then
echo "CRITICAL: Galera cluster status is $ready (ON expected)"
exit 2
fi
if [ $cluster_size -eq $1 ]; then
echo "OK: Cluster size is $cluster_size"
exit 0
fi
if [ $cluster_size -gt $(( $1 / 2 )) ]; then
echo "WARNING: Cluster size is $cluster_size; $1 expected"
exit 1
fi
if [ $cluster_size -le $(( $1 / 2 )) ]; then
echo "CRITICAL: Cluster size is $cluster_size"
exit 2
fi
echo "UNKNOWN ... or not implemented"
exit 3