From 89b8f8c0ce6f6d71acc1e191a4381d2ad8aeb523 Mon Sep 17 00:00:00 2001 From: nick n <39005454+inphobia@users.noreply.github.com> Date: Mon, 14 Jan 2019 23:02:08 +0100 Subject: [PATCH] allow snmp::info base class in netdisco-do (#486) * allow the use of base snmp::info * dont use . * should have been: dont use $_ * also document some extra features * reword --- bin/netdisco-do | 20 ++++++++++++++++++-- lib/App/Netdisco/Worker/Plugin/Show.pm | 15 ++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/bin/netdisco-do b/bin/netdisco-do index a720361b..9396f61f 100755 --- a/bin/netdisco-do +++ b/bin/netdisco-do @@ -301,14 +301,30 @@ the leaf (such as C or C). 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". +"C". Using "C<::>" as the start of the prefix will test +against the base "C" class. + +As well, SNMP object 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. + +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 in the C<-p> parameter: +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 + +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 =head2 psql diff --git a/lib/App/Netdisco/Worker/Plugin/Show.pm b/lib/App/Netdisco/Worker/Plugin/Show.pm index 52a2ca55..6ec90b90 100644 --- a/lib/App/Netdisco/Worker/Plugin/Show.pm +++ b/lib/App/Netdisco/Worker/Plugin/Show.pm @@ -18,13 +18,14 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { my ($device, $port, $extra) = map {$job->$_} qw/device port extra/; $extra ||= 'interfaces'; my $class = undef; - ($class, $extra) = split(/::([^:]+)$/, $extra); - if ($class and $extra) { - $class = 'SNMP::Info::'.$class; - } - else { - $extra = $class; - undef $class; + 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 $i = App::Netdisco::Transport::SNMP->reader_for($device, $class);