#!/bin/bash ########################################################### # check_network_link Nagios Linux plugin V1.0 11/01/2008 # # Watch ethernet interface link status using ethtool # # # # Originally by Markus Walther which used mii-tool # # Reworked by Dmitry Vayntrub to use ethtool # ########################################################### # # # Usage: # # 1. Copy this script to the nagios plugin-directory # # 2. Set the exec-rights (chmod a+x check_network_link) # # 3. If missing, install "ethtool" # # 4. Allow user nagios execute ethtool in /etc/sudoers: # # Defaults:nagios !requiretty # # nagios ALL=NOPASSWD:/sbin/ethtool # # 5. commands.cfg: $USER1$/check_network_link $ARG1$ # # 6. services.cfg: check_network_link!eth0 # # # ########################################################### # # Exit-Codes: # 0 = $STATE_OK # 1 = $STATE_WARNING # 2 = $STATE_CRITICAL # 3 = $STATE_UNKNOWN # Reading the command-input, defaults to eth0 if undefined NIC=$1 ETHTOOL_REPORT="`sudo /sbin/ethtool ${NIC:-eth0} 2>&1`" LINK_STATUS=`echo "$ETHTOOL_REPORT" | grep Link | cut -d \ -f 3` if [ "$LINK_STATUS" = "yes" ] then LINK_SPEED_RPT=`echo "$ETHTOOL_REPORT" | grep "Speed:"` if [ -z `echo $LINK_SPEED_RPT | grep -v 100` ] then # Interface works fine echo "LINK OK - carrier ok, $LINK_SPEED_RPT" exit 0 else # Interface works, but the link speed is slow or unexpected echo "LINK WARNING - carrier ok, but slow or unexpected link speed - $LINK_SPEED_RPT" exit 1 fi elif [ "$LINK_STATUS" = "no" ] then # Link Down - Critical echo "LINK CRITICAL - carrier not detected" exit 2 elif [ -n "`echo $ETHTOOL_REPORT | grep link | grep 'No such device'`" ] then echo "$ETHTOOL_REPORT" #| grep link # Interface not found exit 2 elif [ -n "`echo $ETHTOOL_REPORT | grep sudo`" ] then echo "Add \"Defaults:nagios !requiretty\" in /etc/sudoers" # Unknown if there is no tty for nagios exit 3 else echo "$ETHTOOL_REPORT" echo "Unknown error" # Another error? exit 3 fi