summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/snmp/if-mib-alias24
1 files 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";