diff --git a/check_bond/Makefile b/check_bond/Makefile new file mode 100644 index 0000000..cf9673d --- /dev/null +++ b/check_bond/Makefile @@ -0,0 +1,3 @@ +#/usr/bin/make -f + +include ../common.mk diff --git a/check_bond/check_bond b/check_bond/check_bond new file mode 100644 index 0000000..b292149 --- /dev/null +++ b/check_bond/check_bond @@ -0,0 +1,149 @@ +#!/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 +# +# 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 . +# It will also warn if the Currently Active Slave is not the expected primary interface, +# the default primary interface is eth0, You can override this with -p +# -p can be a comma separated list like "-p eno49,eno50" + +# if you have dont_blame_nrpe=1 set you can choose to +# command[check_bond]=/usr/lib/nagios/plugins/check_bond -i $ARG1$ -p $ARG2$ +# +# define service { +# use generic-service +# service_description Bond state +# check_command check_nrpe!check_bond +# or +# check_command check_nrpe!check_bond!bond1 +# or +# check_command check_nrpe!check_bond!bond1!eth1 +#} +# + +# ------------------------------------------ +# ######## 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 +# B.Potts 2017-01-16 Check and display expected primary interface on bond +# J.Guldmyr 2018-09-25 Check for a list of primary interfaces instead of a single one +# +# +# SETTINGS +# Default if is bond0 +if=bond0 +# Default pri is eth0 +pri=eth0 + +# commands +GREP=/bin/grep +AWK=/usr/bin/gawk +LSMOD=/sbin/lsmod + +# FUNCTIONS +get_options () { + [ $# -gt 0 ]||result 5 + while getopts "i:p:" opt;do + case ${opt} in + i) export if=`echo ${OPTARG}` ;; + p) export pri=`echo ${OPTARG}` ;; + *) result 5;; + esac +done +} + +result () { + case $1 in + 0) echo "OK: - Bondingmode: $(grep "Bonding Mode:" /proc/net/bonding/${if}), active link: $2";; + 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 ] [-p ]";rc=3;; + 6) echo "CRITICAL: bondinterface ${if} has no active slaves";rc=2;; + 7) echo "WARNING: Bondingmode: $(grep "Bonding Mode:" /proc/net/bonding/${if}), (unexpected) active link: $2";rc=1;; + 8) echo "WARNING: bondinterface with name ${if} has less than 2 interfaces - so zero redundancy";rc=1;; + esac +} + +# SCRIPT +# 1st set default return code: +rc=0 + +# test if this script was called correctly +[ $# -eq 1 -o $# -eq 3 -o $# -gt 4 ] && result 5 +[ $rc -gt 0 ] && exit $rc + +[ $# -eq 2 -o $# -eq 4 ] && 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 + +case $(grep "Bonding Mode:" /proc/net/bonding/${if}) in + *"IEEE 802.3ad Dynamic link aggregation"*) bondingmode=lacp;; + *) bondingmode=masterslave;; +esac + +# Inspect the state of the entire bond interface +if [ "$bondingmode" == "lacp" ] +then + ifstate=$(${AWK} '/MII Status:/ {print $3}' /proc/net/bonding/bond0 | head -n 1) + ifslavecount=$(${AWK} '/Slave Interface:/ {print $3}' /proc/net/bonding/bond0 | wc -l) + [ "${ifstate}" != "up" ]&& result 6 + [[ "${pri}" =~ "${ifstate}" ]] || result 7 "${ifstate}" + [ ${ifslavecount} -lt 2 ]&& result 8 +else + ifstate=$(${AWK} '/Currently Active Slave/ {print $4}' /proc/net/bonding/${if}) + [ "${ifstate}" = "None" ]&& result 6 + [[ "${pri}" =~ "${ifstate}" ]] || result 7 "${ifstate}" + [ $rc -gt 0 ] && exit $rc +fi + +# 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 "${ifstate}" +exit $rc + +#END + diff --git a/check_bond/control b/check_bond/control new file mode 100644 index 0000000..f594494 --- /dev/null +++ b/check_bond/control @@ -0,0 +1,4 @@ +Homepage: https://raw.githubusercontent.com/aswen/nagios-plugins/master/check_bond +Uploaders: Jan Wagner +Description: plugin that checks for the status of bonding interfaces. +Recommends: gawk diff --git a/check_bond/copyright b/check_bond/copyright new file mode 100644 index 0000000..9d619ab --- /dev/null +++ b/check_bond/copyright @@ -0,0 +1,17 @@ +Copyright (c) 2010 L.Gill +Copyright (c) 2011 Alexander Swen + +License: ISC license + + Permission to use, copy, modify, and/or 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. +