-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeepalived
executable file
·77 lines (65 loc) · 1.93 KB
/
keepalived
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
#!/bin/bash
# Set the DEBUG to true if you want the
# script to output which IPS are offline
# Default: false
#%# family=auto
#%# capabilities=autoconf
DEBUG=0
if [ "$1" == "autoconf" ]; then
if [ -f /etc/keepalived/keepalived.conf ]; then
echo yes
exit 0
else
echo no
exit 0
fi
fi
# Start of script:
STATE=`cat /etc/keepalived/keepalived.conf | grep -i state | awk '{print $2}'`
IPS=`cat /etc/keepalived/keepalived.conf | sed -n "/virtual_ipaddress/{:a;n;/}/b;p;ba}" | sed "s/address//g" | awk '{print $1}' | cut -d"/" -f1 | grep -v '^$'`
[ ${DEBUG} -gt 0 ] && echo -e "Following IP's need to be online:\t" $IPS
BINDED_IPS=`ip addr list |grep inet |cut -d' ' -f6|cut -d/ -f1`
[ ${DEBUG} -gt 0 ] && echo -e "Following IP's are now online:\t\t" $BINDED_IPS
# Usage: in_array "$needle" "${haystack[@]}"
in_array() {
local hay needle=$1
shift
for hay; do
[[ $hay == $needle ]] && return 0
done
return 1
}
AMOUNT_IPS=0
AMOUNT_ACTIVE_IPS=0
for name in ${IPS[@]}
do
let AMOUNT_IPS=AMOUNT_IPS+1
let AMOUNT_ACTIVE_IPS=AMOUNT_ACTIVE_IPS+1
in_array $name $BINDED_IPS
if [ "$?" -ne "0" ]; then
let AMOUNT_ACTIVE_IPS=AMOUNT_ACTIVE_IPS-1
[ ${DEBUG} -gt 0 ] && echo "Not online: "$name
fi
done
case $1 in
config)
echo 'graph_order config active'
echo 'graph_title Keepalived setting'
echo 'graph_args --base 1000 -l 0'
echo "graph_vlabel Active IP's ($STATE)"
echo 'graph_category network'
echo 'graph_info This graph shows the amount of active IP addresses on the server'
echo 'config.label Configured IP addresses'
# echo 'config.type COUNTER'
echo 'active.label Active IP addresses'
# echo 'active.type COUNTER'
if [ "${STATE}" = "MASTER" ]; then
CRITICAL=$AMOUNT_ACTIVE_IPS
let CRITICAL=CRITICAL-1
echo "active.critical " $CRITICAL":"
fi
exit 0
;;
esac
echo "active.value $AMOUNT_ACTIVE_IPS"
echo "config.value $AMOUNT_IPS"