forked from aswen/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_bond
executable file
·121 lines (106 loc) · 3.85 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Nagios plugin to monitor Nic Bonding state
#
# Based on check_bond.sh written by L.Gill 10/08/06 - V.1.0 as found on
# http://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check-network-bonding/details
# currently I maintain my own version at https://github.com/aswen/nagios-plugins/blob/master/check_bond
# Copyright (c) 2010 L.Gill
# Copyright (c) 2011 Alexander Swen <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
# Example configuration
#
# Typical this check is placed on a client and runs via nrpe
# So add this to nrpe.cfg:
# command[check_bond]=/usr/lib/nagios/plugins/check_bond
# This should warn when one of the slaves is down and go critical when the whole bond is not available.
# This plugin defaults to bond0. If you have multiple bonds you can tell the script so by adding -i <if>.
# if you have dont_blame_nrpe=1 set you can choose to
# command[check_bond]=/usr/lib/nagios/plugins/check_bond -i $ARG1$
#
# define service {
# use generic-service
# service_description Bond state
# check_command check_nrpe!check_bond
# or
# check_command check_nrpe!check_bond!bond1
#}
#
# ------------------------------------------
# ######## Script Modifications ##########
# ------------------------------------------
# Who When What
# --- ---- ----
# A.Swen 2011-09-07 Add support for other bond module than bond0 (defaults to bond0 however)
# A.Swen 2013-10-11 Remove some obsolete stuff and make the script shorter
#
#
# SETTINGS
# Default if is bond0
if=bond0
# commands
GREP=/bin/grep
AWK=/usr/bin/gawk
LSMOD=/sbin/lsmod
# FUNCTIONS
get_options () {
[ $# -gt 0 ]||usage
while getopts "i:" opt;do
case ${opt} in
i) export if=`echo ${OPTARG}` ;;
*) result 5;;
esac
done
}
result () {
case $1 in
0) echo "OK: - Bondingmode: $(grep "Bonding Mode:" /proc/net/bonding/${if})";;
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;;
5) echo "UNKNOWN: Usage: ${me} [-i <bond interface name>]";rc=3;;
6) echo "CRITICAL: bondinterface ${if} has no active slaves";rc=2;;
esac
}
# SCRIPT
# 1st set default return code:
rc=0
# test if this script was called correctly
[ $# -eq 1 -o $# -gt 2 ] && result 5
[ $rc -gt 0 ] && exit $rc
[ $# -eq 2 ] && get_options $@
[ $rc -gt 0 ] && exit $rc
# 1st we check if bonding module is loaded
[ "$(${LSMOD}|grep bonding)" = "" ] && result 2
[ $rc -gt 0 ] && exit $rc
# test if there is any bond interface with this name
[ -f "/proc/net/bonding/${if}" ] || result 4
[ $rc -gt 0 ] && exit $rc
# Inspect the state of the entire bond interface
ifstate=$(${AWK} '/Currently Active Slave/ {print $4}' /proc/net/bonding/${if})
[ "${ifstate}" = "None" ]&& result 6
[ $rc -gt 0 ] && exit $rc
# test state of each if in bond
ethdevs=$(${AWK} '/Slave Interface/ {print $3}' /proc/net/bonding/${if})
for ethdev in ${ethdevs};do
state=$(${GREP} -A1 "Slave Interface: ${ethdev}" /proc/net/bonding/${if}|${AWK} '/MII Status:/ {print $3}')
if [ "${state}" != "up" ];then
result 3 ${ethdev} ${state}
fi
done
[ $rc -eq 0 ] && result 0
exit $rc
#END