1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
Description: fix RouterUpTime to accept and to use colon options
Author: lukerg <luke@psy.io>
Origin: https://github.com/oetiker/mrtg/pull/106
Bug: https://github.com/oetiker/mrtg/issues/94
Last-Update: 2023-06-21
Index: mrtg/bin/mrtg
===================================================================
--- mrtg.orig/bin/mrtg
+++ mrtg/bin/mrtg
@@ -675,17 +675,19 @@ sub getcurrent {
# (OID:community@host or OID) that may have been specified with the RouterUptime
# target keyword
if( defined $rcfg->{ routeruptime }{ $rou } ) {
- my( $noid, $nloc ) = split( /:/, $rcfg->{ routeruptime }{ $rou }, 2 );
- # If only location (community@host) was specified then
- # move the location details into the right place
- if( $noid =~ /@/ ) {
- $nloc = $noid;
- $noid = undef;
- }
- # If no OID (community@host) was specified use the hardcoded default
- if( not $noid ) {
- $noid = 'sysUptime';
- }
+ my ( $noid, $comm );
+ #break apart at the right most at symbol
+ my( $noidcomm, $nloc ) = $rcfg->{ routeruptime }{ $rou } =~ /^(.*)@([^@]+)$/;
+ debug("base","noidcom $noidcomm and nloc $nloc");
+ #now assess for presence of custom OID for uptime
+ if ($noidcomm =~ /:/ ) {
+ ( $noid, $comm ) = split( /:/, $noidcomm, 2);
+ }
+ else {
+ $noid='sysUptime';
+ $comm=$noidcomm;
+ }
+ debug("base","noid is $noid and comm is $comm");
# If no location (community@host) was specified use values from the
# unique target referred to in the monitored data calculation
if( not $nloc ){
@@ -699,10 +701,10 @@ sub getcurrent {
}
}
- $uploc = $nloc;
+ $uploc = "$comm\@$nloc";
# Get the device uptime if $noid(OID) and $nloc (community@host) have been specified
# one way or the other
- debug('base', "Fetching sysUptime and sysName from: $noid:$nloc");
+ debug('base', "Fetching sysUptime and sysName from: $noid:$uploc");
( $uptime, $name ) = snmpget( $uploc, $rcfg->{ snmpoptions }{ $rou }, $noid, 'sysName');
}
|