#!/bin/sh ############################################### # # Nagios script to check network I/O status # # See usage for command line switches # # NOTE: Because of the method of gathering information, bytes/s values are calculated here, so no wanring/critical values can be set to trigger. # Consequently, this check plugin always returns OK. # This plugin is a means of returning stats to nagios for graphing (recommend DERIVE graph in RRD) # # Created: 2007-09-06 (i.yates@uea.ac.uk) # Updated: 2007-09-06 (i.yates@uea.ac.uk) # ############################################### . /usr/local/nagios/libexec/utils.sh VERSION="1.0" IFCONFIG=/sbin/ifconfig GREP=/bin/grep CUT=/bin/cut FLAG_VERBOSE=FALSE INTERFACE="" LEVEL_WARN="0" LEVEL_CRIT="0" RESULT="" EXIT_STATUS=$STATE_OK ############################################### # ## FUNCTIONS # ## Print usage usage() { echo " check_netio $VERSION - Nagios network I/O check script" echo "" echo " Usage: check_netio {-i} [ -v ] [ -h ]" echo "" echo " -i Interface to check (e.g. eth0)" echo " -v Verbose output (ignored for now)" echo " -h Show this page" echo "" } ## Process command line options doopts() { if ( `test 0 -lt $#` ) then while getopts i:vh myarg "$@" do case $myarg in h|\?) usage exit;; i) INTERFACE=$OPTARG;; v) FLAG_VERBOSE=TRUE;; *) # Default usage exit;; esac done else usage exit fi } # Write output and return result theend() { echo $RESULT exit $EXIT_STATUS } # ## END FUNCTIONS # ############################################# # ## MAIN # # Handle command line options doopts $@ # Do the do BYTES_RX=`$IFCONFIG $INTERFACE | $GREP 'bytes' | $CUT -d":" -f2 | $CUT -d" " -f1` BYTES_TX=`$IFCONFIG $INTERFACE | $GREP 'bytes' | $CUT -d":" -f3 | $CUT -d" " -f1` RESULT="NETIO OK - $INTERFACE: RX=$BYTES_RX, TX=$BYTES_TX" # Quit and return information and exit status theend