Skip to content

Instantly share code, notes, and snippets.

@hashimotor
Last active December 17, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashimotor/5598431 to your computer and use it in GitHub Desktop.
Save hashimotor/5598431 to your computer and use it in GitHub Desktop.
Nagios NIC link monitor plugin
#!/bin/bash
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
while test -n "$1"; do
case "$1" in
--interface|-i)
INTERFACE=$2
shift
;;
--speed|-s)
EXPECT_SPEED=$2
shift
;;
*)
echo "Unknown argument: $1"
exit $UNKNOWN
;;
esac
shift
done
if [ x == x$INTERFACE ]; then
echo "set interface."
elif [ x == x$EXPECT_SPEED ]; then
EXPECT_SPEED=1000
fi
CARRIER=$(cat /sys/class/net/$INTERFACE/carrier)
REAL_SPEED=$(cat /sys/class/net/$INTERFACE/speed)
DORMANT=$(cat /sys/class/net/$INTERFACE/dormant)
if [ x == x$CARRIER ]; then
echo "CRITICAL: Something wrong with interface $INTERFACE, cable exists. "
exit $CRITICAL
elif [ $CARRIER == 0 ]; then
echo "CRITICAL: No link detected in interface $INTERFACE, something wrong with cable. "
exit $CRITICAL
elif [ $REAL_SPEED -lt $EXPECT_SPEED ]; then
echo "CRITICAL: Interface $INTERFACE link at ${REAL_SPEED}Mb/s, expected ${EXPECT_SPEED}Mb/s"
exit $CRITICAL
elif [ $REAL_SPEED -gt $EXPECT_SPEED ]; then
echo "WARNING: Interface $INTERFACE link at ${REAL_SPEED}Mb/s, expected ${EXPECT_SPEED}Mb/s"
exit $WARNING
else
echo "OK: Interface $INTERFACE link at ${REAL_SPEED}Mb/s"
exit $OK
fi
echo "UNKNOWN: Unknown state"
exit $UNKNOWN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment