Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Last active June 1, 2018 16:17
Show Gist options
  • Save ilyaevseev/40d5951ac89973c5446e77370d7216d1 to your computer and use it in GitHub Desktop.
Save ilyaevseev/40d5951ac89973c5446e77370d7216d1 to your computer and use it in GitHub Desktop.
Zabbix check for status of aggregated links under Linux
#!/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 ##
@ilyaevseev
Copy link
Author

ilyaevseev commented Jun 1, 2018

Agent config:

  • UserParameter=network.teamcheck,/etc/zabbix/scripts/teamcheck.sh

Item:

  • name = Team/Bond link status
  • key = network.teamcheck
  • info type = character
  • update interval = 1m
  • history = 7d
  • app = Network

Trigger:

  • name = Team/Bond failure on {HOST.NAME}
  • severity = high
  • expr = {my-linux-teamcheck-template:network.teamcheck.regexp("^OK$")}<>1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment