-
Notifications
You must be signed in to change notification settings - Fork 29
/
kvm_check_bonds.sh
executable file
·51 lines (42 loc) · 1.19 KB
/
kvm_check_bonds.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
#!/bin/bash
bonds="$@"
ERRORS=( )
GOOD=( )
for bond in $bonds; do
state=$(sudo /bin/ovs-appctl bond/show ${bond})
if [ -z "${state}" ]; then
ERRORS+=( "${bond} is missing" )
fi
lacp_status=$(echo "${state}" | grep ^lacp_status | cut -f2 -d\ )
# check slaves
slave_count=0
while read slave_state; do
slave=${slave_state//slave }
slave=${slave//: *}
slave_status=${slave_state//* }
if [ "${slave_status}" == "enabled" ]; then
((slave_count++))
else
ERRORS+=( "${bond}: ${slave} status ${slave_status}" )
fi
done < <(echo "${state}" | grep ^slave)
if [ "${lacp_status}" == "negotiated" ]; then
if [ ${slave_count} -ge 2 ]; then
GOOD+=( "${bond} ${slave_count} slaves enabled" )
else
ERRORS+=( "${bond} only ${slave_count} slaves enabled" )
fi
else
ERRORS+=( "${bond} LACP status '${lacp_status}'" )
fi
done
if [ -z "${ERRORS}" -a -z "${GOOD}" ]; then
echo "UNKNOWN: no bond found"
exit 3
elif [ -z "${ERRORS}" ]; then
echo "OK: ${GOOD}"
exit 0
else
echo "CRITICAL: ${ERRORS}"
exit 2
fi