netdisco / snmp-info

Other
35 stars 31 forks source link

SNMP::Info::Layer2::CiscoSB not using ifAlias (ifDescr) mod #503

Open redaxhu opened 7 months ago

redaxhu commented 7 months ago

Expected Behavior

The Cisco Small Business Sx200-300-500 switch lines return the port description in ifAlias and the current CiscoSB class not using at all.
SNMP::Info::Layer2::CiscoSB should return ifAlias if it exists in the switch, instead of ifDescription.

Current Behavior

same ifName and ifDescr returned

Possible Solution

add the following to SNMP/Info/Layer2/CiscoSB.pm:

--- CiscoSB.pm-orig     2023-10-02 13:39:04.695835044 +0200
+++ CiscoSB.pm-patch    2023-10-02 13:42:19.385422657 +0200
@@ -41,6 +41,8 @@
 use SNMP::Info::CiscoStats;
 use SNMP::Info::CiscoConfig;
 use SNMP::Info::CDP;
+use SNMP::Info::Layer3;
+

 @SNMP::Info::Layer2::CiscoSB::ISA
     = qw/SNMP::Info::Layer2 SNMP::Info::EtherLike
@@ -72,6 +74,7 @@

 %MIBS = (
     %SNMP::Info::Layer2::MIBS,
+    %SNMP::Info::Layer3::MIBS,
     %SNMP::Info::EtherLike::MIBS,
     %SNMP::Info::CiscoStats::MIBS,
     %SNMP::Info::CiscoConfig::MIBS,
@@ -167,6 +170,27 @@
     return $interfaces;
 }

+sub i_description {
+    my $ciscosb = shift;
+    my $partial = shift;
+    my $i_desc  = $ciscosb->orig_i_description($partial);
+    my $i_name  = $ciscosb->i_alias($partial) || {};
+    my $i_index  = $ciscosb->i_index($partial);
+
+    my %if;
+
+    foreach my $iid ( keys %$i_index ) {
+       my $index = $i_index->{$iid};
+       my $pname = $i_name->{$iid};
+       my $name = $i_desc->{$iid};
+       next unless defined $index;
+       $if{$iid} =  defined($pname) && length $pname ? $pname  : $name;
+    }
+
+    return \%if;
+}
+

Your Environment

ollyg commented 6 months ago

Hi @redaxhu many thanks for this! Can you let me know why Layer3::MIBS is needed? It seems a bit odd for the Layer2::CiscoSB class to import that, and I wonder if it's a specific MIB we can just import that instead. (personally I do believe the whole Layer2/Layer3 business is not helpful but we have it in the design)

redaxhu commented 6 months ago

Hi @ollyg , actually you are right, it is working without using the Layer3 too. somehow I though I need Layer3 to access the i_alias() fn.