#1087 netdisco-do show handles qualified MIB leafs

This commit is contained in:
Oliver Gorwits
2023-08-11 10:24:05 +01:00
parent 3e883e163e
commit 21afacccc4
2 changed files with 27 additions and 33 deletions

View File

@@ -323,37 +323,34 @@ create a directory for the output files.
=head2 show =head2 show
Dump the content of an SNMP MIB leaf, which is useful for diagnostics and Dump the content of an SNMP MIB Object or an L<SNMP::Info> method, useful for
troubleshooting. You should provide the "C<-e>" option which is the name of diagnostics and troubleshooting.
the leaf (such as C<interfaces> or C<uptime>).
If you wish to test with a device class other than that discovered, prefix the You should provide the "C<-e>" option which is the name of the method or
leaf with the class short name, for example "C<Layer3::C3550::interfaces>" or object, such as C<interfaces> or C<uptime> or C<ifDescr>.
"C<Layer2::HP::uptime>". Using "C<::>" as the start of the prefix will test
against the base "C<SNMP::Info>" class.
As well, SNMP OID names can be used as an argument for "C<-e>", so you can If you wish to specify the SNMP MIB to load and find the Object in, then
use C<ifName> for example, which will use the netdisco-mibs files for you can qualify the "C<-e>" parameter, such as C<IF-MIB::ifDescr>.
translations.
If you wish to test with a specific L<SNMP::Info> device class other than the
one discovered, pass this in the "C<-p>" parameter, such as C<Layer3> or
C<SNMP::Info::Layer3> (the C<SNMP::Info> prefix is optional).
All "C<-e>" parameters are case sensitive. 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 interfaces
~/bin/netdisco-do show -d 192.0.2.1 -e Layer2::HP::interfaces ~/bin/netdisco-do show -d 192.0.2.1 -e IF-MIB::ifDescr
~/bin/netdisco-do show -d 192.0.2.1 -e ::interfaces ~/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 ~/bin/netdisco-do show -d 192.0.2.1 -e ifName -p Layer3::Arista
A parameter may be passed to the C<SNMP::Info> 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<specify> will show the used configuration for the The "C<-e>" parameter C<specify> will show the used configuration for the
specified device. specified device.
~/bin/netdisco-do show -d 192.0.2.1 -e specify ~/bin/netdisco-do show -d 192.0.2.1 -e specify
This command works well with the "C<-I>" debug flag on L<SNMP::Info> (or
"C<-II>").
=head2 psql =head2 psql
Start an interactive terminal with the Netdisco PostgreSQL database. If you Start an interactive terminal with the Netdisco PostgreSQL database. If you

View File

@@ -15,25 +15,22 @@ register_worker({ phase => 'check' }, sub {
register_worker({ phase => 'main', driver => 'snmp' }, sub { register_worker({ phase => 'main', driver => 'snmp' }, sub {
my ($job, $workerconf) = @_; my ($job, $workerconf) = @_;
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/; my ($device, $class, $object) = 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;
}
}
$class = 'SNMP::Info::'.$class if $class and $class !~ m/^SNMP::Info::/;
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device, $class); 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->() ); Data::Printer::p( $result->() );
return Status->done( return Status->done(
sprintf "Showed %s response from %s", $extra, $device->ip); sprintf "Showed %s response from %s", $orig_object, $device->ip);
}); });
true; true;