60 lines
1.2 KiB
Bash
Executable file
60 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Exit-Codes:
|
|
# 0 = $STATE_OK
|
|
# 1 = $STATE_WARNING
|
|
# 2 = $STATE_CRITICAL
|
|
# 3 = $STATE_UNKNOWN
|
|
|
|
DEVS=`grep '^en' /proc/net/dev | cut -d ':' -f 1`
|
|
BONDS=`grep 'bond[0-9]:' /proc/net/dev | cut -d ':' -f 1`
|
|
|
|
if [[ -z $BONDS ]] ; then
|
|
echo "No bonding interfaces found"
|
|
exit 3
|
|
fi
|
|
|
|
#BONDS="bond0 bond1"
|
|
|
|
if [[ -n $1 ]] ; then
|
|
BONDS=`grep bond <<< $1`
|
|
if [[ -z $BONDS ]] ; then
|
|
echo "$1 not a bonding interface"
|
|
exit 3
|
|
fi
|
|
fi
|
|
|
|
RET=0
|
|
for BOND in $BONDS ; do
|
|
if [[ -d /sys/class/net/$BOND ]] ; then
|
|
MODE=`cut -d ' ' -f 2 /sys/class/net/$BOND/bonding/mode `
|
|
SLAVES=`cat /sys/class/net/$BOND/bonding/slaves`
|
|
echo -n "$BOND mode $MODE"
|
|
for DEV in $SLAVES ; do
|
|
LINKING=`cat /sys/class/net/$DEV/operstate`
|
|
if [[ "$LINKING" == "up" ]] ; then
|
|
echo -n " $DEV up"
|
|
SPEED=`cat /sys/class/net/$DEV/speed`
|
|
if [[ -n $SPEED ]] ; then
|
|
echo -n " $SPEED"
|
|
fi
|
|
else
|
|
echo -n " $DEV down"
|
|
[[ $RET -lt 2 ]] && RET=2
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ $MODE == 1 ]] ; then
|
|
ACTIVE=`cat /sys/class/net/$BOND/bonding/active_slave`
|
|
echo "Active: $ACTIVE"
|
|
else
|
|
echo
|
|
fi
|
|
else
|
|
echo "$BOND Not found in sysfs"
|
|
[[ $RET -lt 1 ]] && RET=2
|
|
fi
|
|
done
|
|
|
|
exit $RET
|