[hobbit@sodn035u tmp]$ diff -u bbmrtg.pl.old bbmrtg.pl --- bbmrtg.pl.old 2008-11-18 13:13:28.000000000 +0100 +++ bbmrtg.pl 2008-11-18 13:19:44.000000000 +0100 @@ -17,12 +17,21 @@ # # Modified by W.J.M. Nelis, user-f4ccfde53c0d@xymon.invalid, 20080602 # - Added scoped variable $prev -# - Changed invokation of RRDs::fetch to use "-s $prev" -# - MRTG recognises options "noi" and "noinfo". When checking for option "noi" +# - Changed invocation of RRDs::fetch to use "-s $prev" +# - MRTG recognizes options "noi" and "noinfo". When checking for option "noi" # include word boundaries in the check. # # Modified by W.J.M. Nelis, user-f4ccfde53c0d@xymon.invalid, 200809 # - Added function MyLocalTime to make a ISO8601-ish date notation +# - Added support for checking the operational state of a link. If variable +# bb*chklink is defined, the value being either the ifIndex of the +# interface or a negative number, the status of the link becomes red +# if the operational state of the link is DOWN. If the value is negative, +# the link is considered down if no input is received, and only a little +# bit of output is sent. +# Added installation constant $GetLinkStatus. +# Added installation constant $ChklinkOutputThreshold. +# - Removed trailing spaces # use strict; @@ -86,6 +95,12 @@ # Define the BACKEND MRTG is using using (RRDtool or just MRTG). my $BACKEND = 'RRD'; # RRD or MRTG +# For the status check of a link, define the output threshold, which is not +# exceeded by background processes, like STP and CDP, and define the command +# to retrieve the operational status of an interface. +my $ChklinkOutputThreshold= 125 ; # Threshold in [B/s] +my $GetLinkStatus= "/usr/bin/snmpget -c public -v 2c %s ifOperStatus.%d" ; + # --- Start of RRDtool BACKEND settings (only used if $BACKEND = 'RRD') # Define your RRD cgi script: mrtg-rrd.cgi or 14all.cgi or routers2.cgi @@ -206,6 +221,7 @@ $targetcfg{'legendo'}{$target} || 'Out'; my $colors = $targetcfg{'colours'}{$target} || 'GREEN#00eb0c,BLUE#1000ff'; my $factor = $targetcfg{'factor'}{$target} || 1; + my $chklink = $targetcfg{'bb*chklink'}{$target} || '' ; # ifIndex or -1 if linkstatus check # Load MRTG parameters from "options" config line my $noo = @@ -353,7 +369,7 @@ } my ($last, $prev, $i_now, $o_now); - if ($BACKEND eq 'MRTG') { + if ($BACKEND eq 'MRTG') { warn "open(MRTG, '$targetLog')\n" if $tron; open(MRTG, $targetLog) or next; ; @@ -432,7 +448,24 @@ ? 'yellow' : 'green'; __COLOR__ } - } else { + # + # If symbol bb*chklink is defined, the test state becomes (also) red if the + # link is down. If bb*chklink is negative, the lack of both input and output + # is sufficient to give an alert. However, if bb*chklink is positive the + # operational state of the interface is checked. The value of bb*chklink + # is the ifIndex of the interface. + # + if ( $i_now == 0 && $o_now <= $ChklinkOutputThreshold && $chklink ) { + if ( $chklink < 0 ) { + $color= 'red' ; # No i/o ==> link down + } else { + my $cmd= sprintf( $GetLinkStatus, $host, $chklink ) ; + my $val= `$cmd` ; + $color= 'red' if $val=~ m/down\(2\)/ ; + } # of else + } # of if + + } else { warn "Time stamp in log is in the future by $timediff secs!\n"; warn "Target: $target, bbfile: $bbfile\n"; warn "current time: $current_time, last $last, stale $mrtgStaleSecs\n"; @@ -959,6 +992,18 @@ Specifies the column in the BB display that this interface will display under on the alternate host. The default value is 'mrtg'. +=item B + +Specify this parameter if the operational state of the interface needs +to be checked too. The value of the parameter is either the SNMP ifIndex +of the interface or a negative number. If specified and the value is the +(positive) ifIndex, the operational state of the interface is checked +if the input rate is 0 bytes per second, and there is only a limited +amount of output. If the interface state is DOWN, the color of the +test will be red. If a negative value is specified, the lack of both +input and output is sufficient to set the color of the test to red. +The default value is not to test the operational state. + =item B =item B