Last active
June 1, 2018 16:17
-
-
Save ilyaevseev/40d5951ac89973c5446e77370d7216d1 to your computer and use it in GitHub Desktop.
Zabbix check for status of aggregated links under Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FAILED="" | |
SLAVES_COUNTER="" | |
cd /sys/class/net/ | |
Check_iface() { | |
local master="$1" slave="$2" mask="$3" | |
#echo "DEBUG: check_iface $master:$slave" | |
SLAVES_COUNTER="x${SLAVES_COUNTER}" | |
ip -oneline link list "$slave" 2>/dev/null | egrep -q "$mask" && return | |
FAILED="${FAILED}${FAILED:+,}$master:$slave" | |
} | |
Check_bond() { | |
slaves="/sys/class/net/$1/bonding/slaves" | |
test -s "$slaves" || return | |
for iface in $(cat "$slaves"); do | |
Check_iface "$1" "$iface" "BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP.+ master $1 .*state UP " | |
done | |
} | |
Check_team() { | |
for f in /sys/class/net/$1/lower_*; do | |
test -L "$f" || continue | |
Check_iface "$1" "${f##*lower_}" "BROADCAST,MULTICAST,UP,LOWER_UP.+ master $1 .*state UP " | |
done | |
} | |
for iface in $(ip -oneline link list | awk -F': ' '{ print $2 }') | |
do | |
SLAVES_COUNTER="" | |
driver="$(ethtool -i "$iface" 2>/dev/null | awk '/^driver: / { print $2 }')" | |
case "$driver" in | |
bonding ) Check_bond "$iface" ;; | |
team ) Check_team "$iface" ;; | |
* ) continue ;; | |
esac | |
case "${SLAVES_COUNTER}" in | |
??* ) ;; | |
* ) FAILED="${FAILED}${FAILED:+,}$1" ;; | |
esac | |
done | |
echo "${FAILED:-OK}" | |
## END ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Agent config:
UserParameter=network.teamcheck,/etc/zabbix/scripts/teamcheck.sh
Item:
Trigger:
{my-linux-teamcheck-template:network.teamcheck.regexp("^OK$")}<>1