-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_keepalived_state.sh
executable file
·65 lines (50 loc) · 1.46 KB
/
check_keepalived_state.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
#!/bin/bash
#
# Standard Icinga return codes
E_SUCCESS="0"
E_WARNING="1"
E_CRITICAL="2"
E_UNKNOWN="3"
# Check arguments
MASTER=$1
SLAVE=$2
IP=$3 # e.g. floating IP we're "keeping alive", e.g. 103.242.49.20
if [ -z $MASTER ]; then
echo "UNKNOWN: No master specified"
exit ${E_UNKNOWN}
fi
if [ -z $SLAVE ]; then
echo "UNKNOWN: No slave specified"
exit ${E_UNKNOWN}
fi
if [ -z $IP ]; then
echo "UNKNOWN: No IP address specified"
exit ${E_UNKNOWN}
fi
# egrep's return codes
ACTIVE="1"
INACTIVE="0"
# ip -4 -o a | awk '{print $4}' | cut -d'/' -f1
MASTER_OUTPUT=$(ssh $MASTER -l root "ip -4 -o a")
SLAVE_OUTPUT=$(ssh $SLAVE -l root "ip -4 -o a")
MASTER_IPS=`echo "$MASTER_OUTPUT" | awk '{print $4}' | cut -d'/' -f1`
SLAVE_IPS=`echo "$SLAVE_OUTPUT" | awk '{print $4}' | cut -d'/' -f1`
MASTER_IS=$(echo "$MASTER_IPS" | egrep -c "^$IP\$")
SLAVE_IS=$(echo "$SLAVE_IPS" | egrep -c "^$IP\$")
if ([ "$MASTER_IS" = "$ACTIVE" ] && [ "$SLAVE_IS" = "$INACTIVE" ]); then
echo "OK: $IP active on master only"
exit ${E_SUCCESS}
fi
if ([ "$MASTER_IS" = "$INACTIVE" ] && [ "$SLAVE_IS" = "$ACTIVE" ]); then
echo "WARNING: $IP has fallen over to slave"
exit ${E_WARNING}
fi
if ([ "$MASTER_IS" = "$ACTIVE" ] && [ "$SLAVE_IS" = "$ACTIVE" ]); then
echo "CRITICAL: $IP active on both master and slave"
exit ${E_CRITICAL}
fi
if ([ "$MASTER_IS" = "$INACTIVE" ] && [ "$SLAVE_IS" = "$INACTIVE" ]); then
echo "CRITICAL: $IP not active on neither master nor slave"
exit ${E_CRITICAL}
fi
exit ${E_UNKNOWN}