#!/bin/bash ############################################################ # # # Watch network-interfaces with Nagios - The simple script # # # # by Markus Walther - www.markuswalther.org # # # ############################################################ # # # Usage: # # 1. Copy this script to the nagios plugin-directory # # 2. Set the exec-rights (chmod a+x check_network) # # 3. If missing, install "mii-tool" # # 4. Comment out "Defaults requiretty" in /etc/sudoers # # and let user nagios execute mii-tool: # # nagios ALL=NOPASSWD:/sbin/mii-tool # # 5. commands.cfg: $USER1$/check_network $ARG1$ # # 6. services.cfg: check_network!eth0 # # # # Now it should work fine :) # # # ############################################################ # # Read the command-input netdev=$1 # # Exit-Codes: # 0 = $STATE_OK # 1 = $STATE_WARNING # 2 = $STATE_CRITICAL # 3 = $STATE_UNKNOWN # If no input was given if [ "$1" = '' ]; then echo "Usage: check_network INTERFACE" echo "Example: ./check_network eth0" echo "Interface not given" exit 3 fi # Interface works fine if [ `/sbin/mii-tool | grep $netdev | grep "link ok" | wc -l 2>&1` == "1" ] then echo `/sbin/mii-tool $netdev ` ##-v | tail -n1` exit 0 # Link Slow Warning: Warning if Interface is on 10 MBit/s elif [ `/sbin/mii-tool | grep $netdev | grep "10 " | wc -l 2>&1` == "1" ] then echo `/sbin/mii-tool $netdev` exit 1 # Link Down - Critical elif [ `/sbin/mii-tool | grep $netdev | grep "no link" | wc -l 2>&1` == "1" ] then echo `/sbin/mii-tool $netdev` exit 2 # Interface not found elif [ `/sbin/mii-tool | grep $netdev | grep "No such device" | wc -l 2>&1` == "0" ] then echo "Interface not found" exit 3 # Unknown if there is no tty for nagios elif [ `/sbin/mii-tool $netdev 2>&1 | cut -d \ -f 1` == "sudo" ] then echo "Comment out [defaults requiretty] in /etc/sudoers" exit 3 # Another error? else echo `/sbin/mii-tool $netdev 2>&1` echo "Unknown error" exit 3 fi