-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_galera_node.sh
executable file
·114 lines (99 loc) · 3.2 KB
/
check_galera_node.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
#!/bin/bash
SCRIPTNAME=`basename $0`
VERSION="v1.0"
AUTHOR="Jamie Reid <[email protected]>; based on a script by Guillaume Coré <[email protected]>"
OK=0
WARN=1
CRIT=2
OTHER=3
print_help() {
echo "Usage: $SCRIPTNAME -u <user> -p <pass> -H <node> [OPTIONS]..."
echo ""
echo " -u MySQL/MariaDB user (REQUIRED)"
echo " -p MySQL/MariaDB password (REQUIRED)"
echo " -H MySQL/MariaDB host to check (REQUIRED)"
echo " -P MySQL/MariaDB port (OPTIONAL; defaults to 3306)"
echo " -w # of nodes before WARNING (OPTIONAL; defaults to -c)"
echo " -c # of nodes before CRITIAL (OPTIONAL; defaults to 2)"
echo " -h Display this message"
echo ""
echo "Examples:"
echo " ./$SCRIPTNAME -u clusteradmin -p supersekrit -H thor.internal"
echo ""
echo "Report bugs on github: https://github.com/jamiereid/nagios-plugins"
exit $OTHER
}
# Set some defaults
DBPORT=3306
CRITVAL=2
# Cycle through arguments
while getopts “hu:p:H:P:w:c:f:” OPTION; do
case $OPTION in
h) print_help; exit $OTHER;;
u) DBUSER=$OPTARG;;
p) DBPASS=$OPTARG;;
H) DBHOST=$OPTARG;;
P) DBPORT=$OPTARG;;
w) WARNVAL=$OPTARG;;
c) CRITVAL=$OPTARG;;
f) fcp=$OPTARG;;
?) echo "Unknown argument: $1"; print_help; exit $OTHER;;
esac
done
# Check for mandatory arguments
if [ -z "$DBUSER" ]; then
echo "argument -u missing"
print_help; exit $OTHER
fi
if [ -z "$DBPASS" ]; then
echo "argument -p missing"
print_help; exit $OTHER
fi
if [ -z "$DBHOST" ]; then
echo "argument -H missing"
print_help; exit $OTHER
fi
# Set WARNVAL
if [ -z "$WARNVAL" ]; then
WARNVAL=$CRITVAL
fi
# Gather results
CLUSTERSIZE=$(mysql -h$DBHOST -P$DBPORT -u$DBUSER -p$DBPASS -B -N -e "show status like 'wsrep_cluster_size'" | cut -f 2)
NODESTATUS=$(mysql -h$DBHOST -P$DBPORT -u$DBUSER -p$DBPASS -B -N -e "show status like 'wsrep_cluster_status'" | cut -f 2)
NODEREADY=$(mysql -h$DBHOST -P$DBPORT -u$DBUSER -p$DBPASS -B -N -e "show status like 'wsrep_ready'" | cut -f 2)
NODECONNECTED=$(mysql -h$DBHOST -P$DBPORT -u$DBUSER -p$DBPASS -B -N -e "show status like 'wsrep_connected'" | cut -f 2)
NODESTATE=$(mysql -h$DBHOST -P$DBPORT -u$DBUSER -p$DBPASS -B -N -e "show status like 'wsrep_local_state_comment'" | cut -f 2)
# Check NODESTATUS is Primary
if [ "$NODESTATUS" != 'Primary' ]; then
echo "CRITICAL: node is not primary"
FINALEXIT=$CRIT
fi
# Check WSREP is ON
if [ "$NODEREADY" != 'ON' ]; then
echo "CRITICAL: node is not ready"
FINALEXIT=$CRIT
fi
# Check Node is connected to cluster
if [ "$NODECONNECTED" != 'ON' ]; then
echo "CRITICAL: node is not connected"
FINALEXIT=$CRIT
fi
# Check that node is in sync
if [ "$NODESTATE" != 'Synced' ]; then
echo "CRITICAL: node is not synced"
FINALEXIT=$CRIT
fi
# Check size of cluster and return appropriately
if [ $CLUSTERSIZE -gt $WARNVAL ]; then
echo "OK: number of NODES = $CLUSTERSIZE"
FINALEXIT=${FINALEXIT-$OK}
elif [ $CLUSTERSIZE -le $CRITVAL ]; then
echo "CRITICAL: number of NODES = $CLUSTERSIZE"
FINALEXIT=$CRITVAL
elif [ $CLUSTERSIZE -le $WARNVAL ]; then
echo "WARNING: number of NODES = $CLUSTERSIZE"
FINALEXIT=${FINALEXIT-$WARNVAL}
else
exit $OTHER
fi
exit $FINALEXIT