[mrtg] cfgmaker: adding noHC[] too liberally

Daniel mrtg1114 at defiant.coloradomesa.edu
Thu Nov 14 22:02:21 CET 2013


Hello MRTG list,

I've searched the mailing list archives that I could find, but didn't
see anything relevant to my situation.

I'm having a bit of a problem with cfgmaker too aggressively marking
interfaces as being "noHC".  There are two corner cases here that I'm
tickling....

Case 1: Virtual interfaces: sometimes the speed returned is 0, so it's
   marked for noHC.
   The returned value is not 'undef', just zero.
   (I'm seeing this on 'unrouted VLAN xxx' interfaces on a
   Cisco 6509.  It has a lot of traffic on some of these
   interfaces.).

Case 2: (This is specific to my environment): I want all interfaces
   enumerated in the mrtg config file, even if they're down.
   One consequence of this for me is that when the interface is
   down, it sees no traffic, so a poll of the ifHCInOctets interface
   counter returns 0, so it's marked for noHC.
   The returned value is not 'undef', just zero.

The logic in mrtg-2.16.2 seemed more sane to me than it does in
the mrtg-2.17.3/4 code.  Would a patch like the following be
considered acceptable?  It's a diff from 2.17.4.

I've included it inline as an attachment.

Thanks,

	- Daniel


diff -ru mrtg-2.17.4.orig/bin/cfgmaker mrtg-2.17.4/bin/cfgmaker
--- mrtg-2.17.4.orig/bin/cfgmaker	2012-01-12 03:29:00.000000000 -0700
+++ mrtg-2.17.4/bin/cfgmaker	2013-11-14 13:42:24.000000000 -0700
@@ -902,11 +902,13 @@
     my $snmphost = v4onlyifnecessary($router, $ipv4only);
 
     if ($router =~ /:[\d.]*:[\d.]*:[\d.]*:[23]/) {
-        my $speed = (snmpget($snmphost, $v3opt, 'ifHighSpeed.'.$if))[0] || 'unknown';
+        my $speed = (snmpget($snmphost, $v3opt, 'ifHighSpeed.'.$if))[0];
+	$speed = 'unknown' unless defined $speed;
         debug('base',"snmpget $snmphost for ifHighSpeed.$if -> $speed Mb/s");
         $SNMP_Session::errmsg = undef;
 	$Net_SNMP_util::ErrorMessage = undef;
-        my $counter = (snmpget($snmphost,$v3opt, 'ifHCInOctets.'.$if))[0] || 'unknown';
+        my $counter = (snmpget($snmphost,$v3opt, 'ifHCInOctets.'.$if))[0];
+	$counter = 'unknown' unless defined $counter;
         debug('base',"snmpget $snmphost for ifHCInOctets.$if -> $counter");
         if( $speed eq 'unknown' or $counter !~ /^\d+$/ or $SNMP_Session::errmsg or $Net_SNMP_util::ErrorMessage){
             $SNMP_Session::errmsg = undef;



-------------- next part --------------
diff -ru mrtg-2.17.4.orig/bin/cfgmaker mrtg-2.17.4/bin/cfgmaker
--- mrtg-2.17.4.orig/bin/cfgmaker	2012-01-12 03:29:00.000000000 -0700
+++ mrtg-2.17.4/bin/cfgmaker	2013-11-14 13:42:24.000000000 -0700
@@ -902,11 +902,13 @@
     my $snmphost = v4onlyifnecessary($router, $ipv4only);
 
     if ($router =~ /:[\d.]*:[\d.]*:[\d.]*:[23]/) {
-        my $speed = (snmpget($snmphost, $v3opt, 'ifHighSpeed.'.$if))[0] || 'unknown';
+        my $speed = (snmpget($snmphost, $v3opt, 'ifHighSpeed.'.$if))[0];
+	$speed = 'unknown' unless defined $speed;
         debug('base',"snmpget $snmphost for ifHighSpeed.$if -> $speed Mb/s");
         $SNMP_Session::errmsg = undef;
 	$Net_SNMP_util::ErrorMessage = undef;
-        my $counter = (snmpget($snmphost,$v3opt, 'ifHCInOctets.'.$if))[0] || 'unknown';
+        my $counter = (snmpget($snmphost,$v3opt, 'ifHCInOctets.'.$if))[0];
+	$counter = 'unknown' unless defined $counter;
         debug('base',"snmpget $snmphost for ifHCInOctets.$if -> $counter");
         if( $speed eq 'unknown' or $counter !~ /^\d+$/ or $SNMP_Session::errmsg or $Net_SNMP_util::ErrorMessage){
             $SNMP_Session::errmsg = undef;


More information about the mrtg mailing list