forked from aswen/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_bond
executable file
·104 lines (92 loc) · 2.39 KB
/
check_bond
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
#!/bin/bash
# Script to check eth interfaces bonding
# L.Gill 10/08/06 - V.1.0
# A.Swen 11/09/07 - V.1.1
# ------------------------------------------
# ######## Script Modifications ##########
# ------------------------------------------
# Who When What
# --- ---- ----
# A.Swen 2011-09-07 Add support for other bond module than bond0 (defaults to bond0 however)
#
#
# SETTINGS
# Defautl if is bond0
if=bond0
# commands
CAT=/bin/cat
GREP=/bin/grep
EGREP=/bin/egrep
AWK=/usr/bin/gawk
FIND=/usr/bin/find
SED=/bin/sed
WC=/usr/bin/wc
TAIL=/usr/bin/tail
ECHO=/bin/echo
LS=/bin/ls
TR=/usr/bin/tr
LSMOD=/sbin/lsmod
# FUNCTIONS
die () {
rc=$1
shift
echo "==========================">&2
echo "==== FATAL ERROR ====" >&2
echo "==========================">&2
echo "" >&2
echo $@ >&2
exit $rc
}
usage () {
echo "==========================" >&2
echo "==== USAGE ====" >&2
echo "==========================" >&2
echo "" >&2
echo "Usage: ${me} [-i <bond interface name>]" >&2
echo "" >&2
echo "if no option is given this script assumes it has to check bond0" >&2
echo "" >&2
echo "example: ${me} -i bond1" >&2
echo "" >&2
exit 1
}
cleanup () {
for tmpfile in ${BONDTMP} ${ETHLIST} ${ETHS} ${ETHDOWN};do
[ -n "${tempfile}" -a -f "${tmpfile}" ] && rm -f ${tmpfile}
done
}
get_options () {
[ $# -gt 0 ]||usage
while getopts "i:" opt;do
case ${opt} in
i) export if=`echo ${OPTARG}` ;;
*) usage;;
esac
done
}
result () {
case $1 in
0) echo "OK: - Bondingmode: $(grep "Bonding Mode:" /proc/net/bonding/${if})";rc=0 ;;
1) echo "UNKNOWN: plugin error";rc=3;;
2) echo "CRITICAL: bonding module not loaded";rc=2;;
3) echo "WARNING: state of ${if} device $2 is $3";rc=1;;
4) echo "UNKNOWN: no bondinterface with name ${if} found";rc=3;;
esac
cleanup
exit $rc
}
# SCRIPT
[ $# -eq 1 -o $# -gt 2 ] && usage
[ $# -eq 2 ] && get_options $@
# 1st we check if bonding module is loaded
[ "$(${LSMOD}|grep bonding)" = "" ] && result 2
# test if there is any bond interface with this name
[ -f "/proc/net/bonding/${if}" ] || result 4
# test state of each if in bond
${GREP} "Slave Interface" /proc/net/bonding/${if} |awk '{print $3}'|while read ethdev;do
state=$(grep -A1 "Slave Interface: ${ethdev}" /proc/net/bonding/${if}|tail -1|awk '{print $3}')
[ "${state}" = "up" ]||result 3 ${ethdev} ${state}
done
# if we make it here we're ok
result 0
#END