From 21afacccc46f2f1b61e71ae33c78fb0d0d10b114 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 11 Aug 2023 10:24:05 +0100 Subject: [PATCH] #1087 netdisco-do show handles qualified MIB leafs --- bin/netdisco-do | 35 ++++++++++++-------------- lib/App/Netdisco/Worker/Plugin/Show.pm | 25 ++++++++---------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/bin/netdisco-do b/bin/netdisco-do index d93c43bf..70409489 100755 --- a/bin/netdisco-do +++ b/bin/netdisco-do @@ -323,37 +323,34 @@ create a directory for the output files. =head2 show -Dump the content of an SNMP MIB leaf, which is useful for diagnostics and -troubleshooting. You should provide the "C<-e>" option which is the name of -the leaf (such as C or C). +Dump the content of an SNMP MIB Object or an L method, useful for +diagnostics and troubleshooting. -If you wish to test with a device class other than that discovered, prefix the -leaf with the class short name, for example "C" or -"C". Using "C<::>" as the start of the prefix will test -against the base "C" class. +You should provide the "C<-e>" option which is the name of the method or +object, such as C or C or C. -As well, SNMP OID names can be used as an argument for "C<-e>", so you can -use C for example, which will use the netdisco-mibs files for -translations. +If you wish to specify the SNMP MIB to load and find the Object in, then +you can qualify the "C<-e>" parameter, such as C. + +If you wish to test with a specific L device class other than the +one discovered, pass this in the "C<-p>" parameter, such as C or +C (the C prefix is optional). All "C<-e>" parameters are case sensitive. ~/bin/netdisco-do show -d 192.0.2.1 -e interfaces - ~/bin/netdisco-do show -d 192.0.2.1 -e Layer2::HP::interfaces - ~/bin/netdisco-do show -d 192.0.2.1 -e ::interfaces - ~/bin/netdisco-do show -d 192.0.2.1 -e ifName - -A parameter may be passed to the C method or SNMP object in the -"C<-p>" parameter: - - ~/bin/netdisco-do show -d 192.0.2.1 -e has_layer -p 3 - ~/bin/netdisco-do show -d 192.0.2.1 -e ifName -p 2 + ~/bin/netdisco-do show -d 192.0.2.1 -e IF-MIB::ifDescr + ~/bin/netdisco-do show -d 192.0.2.1 -e interfaces -p SNMP::Info::Layer2::HP + ~/bin/netdisco-do show -d 192.0.2.1 -e ifName -p Layer3::Arista The "C<-e>" parameter C will show the used configuration for the specified device. ~/bin/netdisco-do show -d 192.0.2.1 -e specify +This command works well with the "C<-I>" debug flag on L (or +"C<-II>"). + =head2 psql Start an interactive terminal with the Netdisco PostgreSQL database. If you diff --git a/lib/App/Netdisco/Worker/Plugin/Show.pm b/lib/App/Netdisco/Worker/Plugin/Show.pm index bf5728b9..6d1db9c8 100644 --- a/lib/App/Netdisco/Worker/Plugin/Show.pm +++ b/lib/App/Netdisco/Worker/Plugin/Show.pm @@ -15,25 +15,22 @@ register_worker({ phase => 'check' }, sub { register_worker({ phase => 'main', driver => 'snmp' }, sub { my ($job, $workerconf) = @_; - my ($device, $port, $extra) = map {$job->$_} qw/device port extra/; - - $extra ||= 'interfaces'; my $class = undef; - my @values = split /::/, $extra; - $extra = pop @values; - if (scalar(@values)) { - $class = "SNMP::Info"; - foreach my $v (@values) { - last if ($v eq ''); - $class = $class.'::'.$v; - } - } + my ($device, $class, $object) = map {$job->$_} qw/device port extra/; + $class = 'SNMP::Info::'.$class if $class and $class !~ m/^SNMP::Info::/; my $snmp = App::Netdisco::Transport::SNMP->reader_for($device, $class); - my $result = sub { eval { $snmp->$extra($port) } || undef }; + + $object ||= 'interfaces'; + my $orig_object = $object; + my ($mib, $leaf) = split m/::/, $object; + SNMP::loadModules($mib) if $mib and $leaf and $mib ne $leaf; + $object =~ s/[-:]/_/g; + + my $result = sub { eval { $snmp->$object() } || undef }; Data::Printer::p( $result->() ); return Status->done( - sprintf "Showed %s response from %s", $extra, $device->ip); + sprintf "Showed %s response from %s", $orig_object, $device->ip); }); true;