summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--scripts/vyatta-show-snmp-ifmib136
-rw-r--r--templates/show/snmp/mib/ifmib/ifAlias/node.def2
-rw-r--r--templates/show/snmp/mib/ifmib/ifAlias/node.tag/node.def2
-rw-r--r--templates/show/snmp/mib/ifmib/ifDescr/node.def2
-rw-r--r--templates/show/snmp/mib/ifmib/ifDescr/node.tag/node.def2
-rw-r--r--templates/show/snmp/mib/ifmib/ifIndex/node.def2
-rw-r--r--templates/show/snmp/mib/ifmib/ifIndex/node.tag/node.def2
-rw-r--r--templates/show/snmp/mib/ifmib/node.def2
-rw-r--r--templates/show/snmp/mib/node.def1
10 files changed, 152 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index caf9460..fe214da 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,7 @@ bin_SCRIPTS += scripts/show-dhcp-leases.pl
bin_SCRIPTS += scripts/vyatta-boot-image.pl
bin_SCRIPTS += scripts/vyatta-sudo
bin_SCRIPTS += scripts/vyatta-show-snmp.pl
+bin_SCRIPTS += scripts/vyatta-show-snmp-ifmib
bin_SCRIPTS += scripts/rename-image.pl
bin_SCRIPTS += scripts/show-image-storage.pl
bin_SCRIPTS += scripts/vyatta-remote-copy.pl
diff --git a/scripts/vyatta-show-snmp-ifmib b/scripts/vyatta-show-snmp-ifmib
new file mode 100644
index 0000000..a0647e6
--- /dev/null
+++ b/scripts/vyatta-show-snmp-ifmib
@@ -0,0 +1,136 @@
+#! /usr/bin/perl
+
+# **** License ****
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# This code was originally developed by Vyatta, Inc.
+# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc.
+# All Rights Reserved.
+#
+# Author: Stephen Hemminger
+# Date: Novemember 2010
+# Description: Script for show snmp ifmib
+#
+# **** End License ****
+
+use strict;
+use warnings;
+use Getopt::Long;
+
+# This is used to show values corresponding to to results IF-MIB.
+my %interfaces;
+
+sub show_ifindex {
+ foreach my $ifname (@_) {
+ my $info = $interfaces{$ifname};
+ my $ifindex = $info->{'ifIndex'};
+ printf "%s: ifIndex = %d\n", $ifname, $ifindex;
+ }
+}
+
+sub show_ifalias {
+ foreach my $ifname (@_) {
+ my $info = $interfaces{$ifname};
+ my $ifalias = $info->{'ifAlias'};
+ printf "%s: ifAlias = %s\n", $ifname,
+ defined($ifalias) ? $ifalias : $ifname;
+ }
+}
+
+sub read_sysfs {
+ my $filename = shift;
+
+ open( my $f, '<', $filename )
+ or return; # not a PCI device
+
+ my $val = <$f>;
+ close $f;
+ chomp $val;
+ return $val;
+}
+
+# Imitate code in net-snmp to lookup PC
+# TODO - move to common code extension (and handle USB?)
+sub pci_info {
+ my $ifname = shift;
+ my $vendor_id = read_sysfs("/sys/class/net/$ifname/device/vendor");
+ my $device_id = read_sysfs("/sys/class/net/$ifname/device/device");
+
+ return unless ( defined($vendor_id) && defined($device_id) );
+
+ open( my $pci, '-|', "lspci -m -d $vendor_id:$device_id" )
+ or die "Can't run lspci";
+ my $info = <$pci>;
+ close $pci;
+
+ return unless $info;
+
+ # extract vendor and device description from output
+ $info =~ /^\S+ "[^"]*" "([^"]*)" "([^"]*)"/;
+
+ return "$1 $2";
+}
+
+sub show_ifdescr {
+ foreach my $ifname (@_) {
+ my $ifdescr = pci_info($ifname);
+
+ printf "%s: ifDescr = %s\n", $ifname,
+ defined($ifdescr) ? $ifdescr : $ifname;
+ }
+}
+
+sub show_all {
+ foreach my $ifname (@_) {
+ my $info = $interfaces{$ifname};
+ my $ifindex = $info->{'ifIndex'};
+ my $ifalias = $info->{'ifAlias'};
+ my $ifdescr = pci_info($ifname);
+
+ printf "%s: ifIndex = %d\n", $ifname, $ifindex;
+
+ my $pad = sprintf( "%-*s", length($ifname) + 1, " " );
+ printf "%s ifAlias = %s\n", $pad, $ifalias if ($ifalias);
+ printf "%s ifDescr = %s\n", $pad, $ifdescr if ($ifdescr);
+ }
+}
+
+my $show = \&show_all;
+
+GetOptions(
+ "ifindex" => sub { $show = \&show_ifindex },
+ "ifalias" => sub { $show = \&show_ifalias },
+ "ifdescr" => sub { $show = \&show_ifdescr },
+) or die "Unknown option\n";
+
+# List of all interfaces that currently exist on system
+# includes interfaces that may be outside Vyatta CLI because
+# they still show up in SNMP
+open( my $ip, '-|', 'ip li' )
+ or die "Can't run ip command\n";
+
+my $ifname;
+while (<$ip>) {
+ if (/^(\d+): ([^:]*): /) {
+ $ifname = $2;
+ $interfaces{$ifname} = { 'ifIndex' => $1 };
+ }
+ elsif (/^ +alias (.*)$/) {
+ $interfaces{$ifname}->{'ifAlias'} = $1;
+ }
+}
+close $ip;
+
+if (@ARGV) {
+ $show->(@ARGV);
+}
+else {
+ $show->( sort keys %interfaces );
+}
diff --git a/templates/show/snmp/mib/ifmib/ifAlias/node.def b/templates/show/snmp/mib/ifmib/ifAlias/node.def
new file mode 100644
index 0000000..91a0aa0
--- /dev/null
+++ b/templates/show/snmp/mib/ifmib/ifAlias/node.def
@@ -0,0 +1,2 @@
+help: Show SNMP ifAlias for all interfaces
+run: ${vyatta_bindir}/vyatta-show-snmp-ifmib --ifalias
diff --git a/templates/show/snmp/mib/ifmib/ifAlias/node.tag/node.def b/templates/show/snmp/mib/ifmib/ifAlias/node.tag/node.def
new file mode 100644
index 0000000..6c5b00a
--- /dev/null
+++ b/templates/show/snmp/mib/ifmib/ifAlias/node.tag/node.def
@@ -0,0 +1,2 @@
+help: Show SNMP ifAlias for specified interface
+run: ${vyatta_bindir}/vyatta-show-snmp-ifmib --ifalias $6
diff --git a/templates/show/snmp/mib/ifmib/ifDescr/node.def b/templates/show/snmp/mib/ifmib/ifDescr/node.def
new file mode 100644
index 0000000..6ec827d
--- /dev/null
+++ b/templates/show/snmp/mib/ifmib/ifDescr/node.def
@@ -0,0 +1,2 @@
+help: Show SNMP ifDescr for all interfaces
+run: ${vyatta_bindir}/vyatta-show-snmp-ifmib --ifdescr
diff --git a/templates/show/snmp/mib/ifmib/ifDescr/node.tag/node.def b/templates/show/snmp/mib/ifmib/ifDescr/node.tag/node.def
new file mode 100644
index 0000000..95222de
--- /dev/null
+++ b/templates/show/snmp/mib/ifmib/ifDescr/node.tag/node.def
@@ -0,0 +1,2 @@
+help: Show SNMP ifDescr for specified interface
+run: ${vyatta_bindir}/vyatta-show-snmp-ifmib --ifdescr $6
diff --git a/templates/show/snmp/mib/ifmib/ifIndex/node.def b/templates/show/snmp/mib/ifmib/ifIndex/node.def
new file mode 100644
index 0000000..2955c1d
--- /dev/null
+++ b/templates/show/snmp/mib/ifmib/ifIndex/node.def
@@ -0,0 +1,2 @@
+help: Show SNMP ifIndex for all interfaces
+run: ${vyatta_bindir}/vyatta-show-snmp-ifmib --ifindex
diff --git a/templates/show/snmp/mib/ifmib/ifIndex/node.tag/node.def b/templates/show/snmp/mib/ifmib/ifIndex/node.tag/node.def
new file mode 100644
index 0000000..f9159ac
--- /dev/null
+++ b/templates/show/snmp/mib/ifmib/ifIndex/node.tag/node.def
@@ -0,0 +1,2 @@
+help: Show SNMP ifIndex for specified interface
+run: ${vyatta_bindir}/vyatta-show-snmp-ifmib --ifindex $6
diff --git a/templates/show/snmp/mib/ifmib/node.def b/templates/show/snmp/mib/ifmib/node.def
new file mode 100644
index 0000000..fa309ff
--- /dev/null
+++ b/templates/show/snmp/mib/ifmib/node.def
@@ -0,0 +1,2 @@
+help: Show SNMP interfaces MIB information
+run: ${vyatta_bindir}/vyatta-show-snmp-ifmib
diff --git a/templates/show/snmp/mib/node.def b/templates/show/snmp/mib/node.def
new file mode 100644
index 0000000..de4f01b
--- /dev/null
+++ b/templates/show/snmp/mib/node.def
@@ -0,0 +1 @@
+help: Show SNMP MIB information