check_mrtgtraf question

Cook, Garry gwcook at arcadis-us.com
Mon Jan 8 18:44:41 CET 2007


-----Original Message-----
>Quick question- I currently use MRTG to monitor the traffic on a number
of my routers, and
[snip]
>I have been considering switching MRTG over to a RRD logging format, so
I can use things
[snip]
>what other options might I have so as to not lose the monitoring
functionality of the check_mrtgtraf plug-in? Thanks!

There might be other plugins out there that monitor RRDs, I'm not sure.
I wrote one a while back for use on datacenter switch uplinks. It's a
simple shell script plugin, but you might find it useful. Feel free to
hack away and release it if you and/or others might find it useful.


#!/bin/sh
########################################################################
########
#
# CHECK_RRD_BW plugin for Nagios
#
# Written by Garry W. Cook <gwc at cookbros.net>
#
#
# Description:
# This plugin will read the current value from an rrd file and compare
with
# warning and critical values, for either inbound or outbound bandwidth
# parameters.
#
#  Notes:
#   - This plugin requires:
#       rrdtool
#       awk
#
#
# Example checkcommands.cfg entry:
#
# 'check_rrd' command definition
#define command{
#       command_name    check_rrd_bw.sh
#       command_line    $USER1$/check_rrd $ARG1$ $ARG2$ $ARG3$ $ARG4$
[$ARG5$]
#       }
#
#
# Edit the following variables to match your system.
# RRDTOOL Binary Directory
RRDTOOL="/usr/local/rrdtool/bin"
# RRD Files Directory
RRDFILES="/var/www/html/mrtg/rrdfiles"

#
# Nothing to change below this line
#

PROGNAME=`basename $0`
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.4 $' | sed -e 's/[^0-9.]//g'`


. $PROGPATH/utils.sh

print_usage() {
        echo ""
        echo "Usage:"
        echo " $0 [-bkmg] <rrdfile> <in|out> <warning> <critical>"
        echo " $0 (-V | --version)"
        echo " $0 (-h | --help)"
        echo ""
        # Need to change this to ranges in future
        echo "Warning and critical thresholds are MAX values,"
        echo "going above the threshold will trigger an alert."
        echo ""
        echo "Labels and multiplier for warning and critical values"
        echo "are determined by the first argument:"
        echo "B=bps; K=Kbps (Default); M=Mbps; G=Gbps" 
        echo ""
}

print_help() {
        print_revision $PROGNAME $REVISION
        print_usage
        echo "Nagios Plugin: Check Bandwidth within an RRD."
        echo ""
        support
}


exitstatus=$STATE_UNKNOWN #default

# Check for --help, etc.
case $1 in
    -V)
        print_revision
        exit $STATE_UNKNOWN
        ;;
    --version)
        print_revision
        exit $STATE_UNKNOWN
        ;;
    -h)
        print_help
        exit $STATE_UNKNOWN
        ;;
    --help)
        print_help
        exit $STATE_UNKNOWN
        ;;
esac

# Verify correct number of arguments
if [ $# -lt 4 ]; then
    print_usage
    exit $STATE_UNKNOWN
fi

while [ $# -eq 5 ];do
    case $1 in
        B)
            LABEL=""
            DIV="1000"
            ;;
        K)
            LABEL="$1"
            DIV="100000"
            ;;
        M)
            LABEL="$1"
            DIV="1000000"
            ;;
        G)
            LABEL="$1"
            DIV="1000000000"
            ;;
        *)
            echo "$1 not a valid Label/Multiplier"
            exit $STATE_UNKNOWN
            ;;
    esac
    shift
done

FILE=$1
BW=$2
WARNING=$3
CRITICAL=$4

########################################################################
#######################
# Hmmm... Am I multiplying by 8 to get Bytes and then dividing by an
extra 100 to get bits??? #
########################################################################
#######################

# Verify file exists and calculate current inbound or outbound bandwidth
if [ -e "$RRDFILES/$FILE" ]; then
    if [ $BW = "in" ]; then
        VALUE="$($RRDTOOL/rrdtool fetch $RRDFILES/$FILE AVERAGE -s
-5minutes | awk 'BEGIN { IFS=":" } NR==3 { printf("%d\n", $2 * 8) }')"
    elif [ $BW = "out" ]; then
        VALUE="$($RRDTOOL/rrdtool fetch $RRDFILES/$FILE AVERAGE -s
-5minutes | awk 'BEGIN { IFS=":" } NR==3 { printf("%d\n", $3 * 8) }')"
    fi
    
    if [ $(($VALUE/${DIV:-100000})) -gt $CRITICAL ]; then
        echo "CRITICAL - Current BW $BW:
$(($VALUE/${DIV:-100000}))"${LABEL:-K}"bps"
        exit $STATE_CRITICAL
    elif [ $(($VALUE/${DIV:-100000})) -gt $WARNING ]; then
        echo "WARNING - Current BW $BW:
$(($VALUE/${DIV:-100000}))"${LABEL:-K}"bps"
        exit $STATE_WARNING
    else
        echo "OK - Current BW $BW:
$(($VALUE/${DIV:-100000}))"${LABEL:-K}"bps"
        exit $STATE_OK
    fi
else
    echo "$RRDFILES/$FILE does not exist."
    exit $STATE_UNKNOWN
fi

exit $exitstatus

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list