From 6689df5d9b09d215ec98f0080da5fd5f61f12da8 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 7 Mar 2011 16:08:00 -0800 Subject: Fix SNMP ifAlias for more than 10 devices Bug 6853 Handle OID format when ifIndex is 10 or greater. Needed to fix regex parsing. Also allow symbolic OID. --- scripts/snmp/if-mib-alias | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/snmp/if-mib-alias b/scripts/snmp/if-mib-alias index d8b3ea9f..d17644e9 100755 --- a/scripts/snmp/if-mib-alias +++ b/scripts/snmp/if-mib-alias @@ -24,20 +24,20 @@ use strict; use warnings; use feature "switch"; -# Collect interface alias values +# Collect interface all alias values sub get_alias { my @interfaces; open (my $ip, '-|', 'ip li') - or die "Can't run ip command\n"; + or die "Can't run ip command\n"; my $index; while(<$ip>) { - if (/^(\d+): ([^:]*): /) { - $index = $1; - $interfaces[$index] = $2; - } elsif (/^ +alias (.*)$/) { - $interfaces[$index] = $1; - } + if (/^(\d+): ([^:]*): /) { + $index = $1; + $interfaces[$index] = $2; + } elsif (/^ +alias (.*)$/) { + $interfaces[$index] = $1; + } } close $ip; return @interfaces; @@ -46,7 +46,8 @@ sub get_alias { sub get_oid { my $oid = shift; die "Not a valid Object ID: $oid" - unless ($oid =~ /^[0-9.]*\.(\d)$/); + unless ($oid =~ /.(\d+)$/); + my $ifindex = $1; my @interfaces = get_alias(); @@ -54,6 +55,7 @@ sub get_oid { print "$oid\nstring\n$ifalias\n" if $ifalias; } +# OID of ifAlias [RFC2863] my $BASE = '.1.3.6.1.2.1.31.1.1.1.18'; sub get_next { @@ -63,7 +65,7 @@ sub get_next { if ($oid eq $BASE); die "Not a valid Object ID: $oid" - unless ($oid =~ /^([0-9.]*)\.(\d+)$/); + unless ($oid =~ /^(\S*)\.(\d+)$/); my $base = $1; my $ifindex = $2; @@ -94,7 +96,7 @@ sub ifindextoname { sub set_oid { my ($oid, $target, $value) = @_; die "Not a valid Object ID: $oid" - unless ($oid =~ /^[0-9.]*\.(\d)$/); + unless ($oid =~ /\.(\d+)$/); my $ifindex = $1; unless ($target eq 'string') { print "wrong-type\n"; -- cgit v1.2.3