I've committed this in scripts/ifAlias, if anyone using the old script wants to test it...
adam.
On 2014-02-12 02:56, Sascha Schaal wrote:
Hi Guys,
while trying your ifAlias Shell-Script, i found it misbehaved on GETNEXT-Operations, which lead to Bogus Output on snmpwalks. I rewrote it in Perl, this should do the trick:
################################################################
#!/usr/bin/perl -w
use strict; use warnings;
my $REQ = $ARGV[0]; my $ROID = $ARGV[1]; my $Base = ".1.3.6.1.2.1.31.1.1.1.18"; my @iface_list = `ip l | grep mtu`; my $index = 0; my %Table; my $p_oid; my $p_type = "STRING"; my $p_desc;
if ($ROID eq $Base){ $index = 0; } else{ my @split = split("$Base.",$ROID); $index = $split[1]; } foreach my $row (@iface_list){ my @split = split(": ", $row); my $desc = `grep "^# $split[1]:" /etc/network/interfaces|sed s/^\#\ $split[1]:\ //`; my ($key, $value) = ("$Base.$split[0]",$desc); $Table{$key} = $value; } if ($REQ eq "-g"){ if ($index == 0){ exit 0; } else{ if( exists($Table{$ROID} ) ) { $p_oid = $ROID; $p_desc = $Table{$ROID}; } else{ print "noSuchName\n"; exit 0; } }
} elsif ($REQ eq "-n"){ for ($index, $index <= keys %Table,$index++){ if( exists($Table{"$Base.$index"} ) ) { $p_oid = "$Base.$index"; $p_desc = $Table{"$Base.$index"}; } else{ exit 0; } } } else{ exit 0; }
print "$p_oid\n"; print "$p_type\n"; print "$p_desc"; exit 0;
################################################################
I hereby grant all Rights to this Code to Adam Armstrong.
Regards,
Sascha Schaal _______________________________________________ observium mailing list observium@observium.org http://postman.memetic.org/cgi-bin/mailman/listinfo/observium