New netdisco-do command "show" for diagnostic reporting

This commit is contained in:
Oliver Gorwits
2014-08-04 22:14:14 +01:00
parent 70531a17f1
commit f63527644a
4 changed files with 34 additions and 11 deletions

View File

@@ -4,6 +4,7 @@
* [#108] Port Bounce port control feature (down and up in succession)
* Support for stuffing other locations into @INC at runtime
* New netdisco-do command "show" for diagnostic reporting
[ENHANCEMENTS]

View File

@@ -11,6 +11,7 @@ requires 'App::cpanminus' => 1.6108;
requires 'App::local::lib::helper' => 0.07;
requires 'Archive::Extract' => 0;
requires 'CGI::Expand' => 2.05;
requires 'Data::Printer' => 0;
requires 'DBD::Pg' => 0;
requires 'DBD::SQLite' => 1.37;
requires 'DBIx::Class' => 0.08250;

View File

@@ -73,7 +73,11 @@ unless ($action) {
# create worker (placeholder object for the role methods)
{
package MyWorker;
use Moo;
use Module::Load ();
use Data::Printer ();
with 'App::Netdisco::Daemon::Worker::Poller::Device';
with 'App::Netdisco::Daemon::Worker::Poller::Arpnip';
with 'App::Netdisco::Daemon::Worker::Poller::Macsuck';
@@ -82,7 +86,6 @@ unless ($action) {
with 'App::Netdisco::Daemon::Worker::Interactive::DeviceActions';
with 'App::Netdisco::Daemon::Worker::Interactive::PortActions';
use Module::Load ();
eval { Module::Load::load 'App::Netdisco::Util::Graph' };
sub graph {
App::Netdisco::Util::Graph::graph();
@@ -94,6 +97,22 @@ unless ($action) {
App::Netdisco::Util::NodeMonitor::monitor();
return ('done', 'Generated monitor data.');
}
use App::Netdisco::Util::SNMP ();
sub show {
$extra ||= 'interfaces'; my $class = undef;
($class, $extra) = split(/::([^:]+)$/, $extra);
if ($class and $extra) {
$class = 'SNMP::Info::'.$class;
}
else {
$extra = $class;
undef $class;
}
my $i = App::Netdisco::Util::SNMP::snmp_connect($device, $class);
Data::Printer::p($i->$extra);
return ('done', "Showed $extra response from $device.");
}
}
my $worker = MyWorker->new();

View File

@@ -43,7 +43,7 @@ Returns C<undef> if the connection fails.
=cut
sub snmp_connect { _snmp_connect_generic(@_, 'read') }
sub snmp_connect { _snmp_connect_generic('read', @_) }
=head2 snmp_connect_rw( $ip )
@@ -54,16 +54,17 @@ Returns C<undef> if the connection fails.
=cut
sub snmp_connect_rw { _snmp_connect_generic(@_, 'write') }
sub snmp_connect_rw { _snmp_connect_generic('write', @_) }
sub _snmp_connect_generic {
my ($ip, $mode) = @_;
my ($mode, $ip, $class) = @_;
$mode ||= 'read';
# get device details from db
my $device = get_device($ip);
my %snmp_args = (
AutoSpecify => 0,
DestHost => $device->ip,
Retries => (setting('snmpretries') || 2),
Timeout => (setting('snmptimeout') || 1000000),
@@ -74,6 +75,7 @@ sub _snmp_connect_generic {
MibDirs => [ _build_mibdirs() ],
IgnoreNetSNMPConf => 1,
Debug => ($ENV{INFO_TRACE} || 0),
DebugSNMP => ($ENV{SNMP_TRACE} || 0),
);
# an override for bulkwalk
@@ -100,12 +102,12 @@ sub _snmp_connect_generic {
: (reverse (1 .. (setting('snmpver') || 3))) );
# use existing or new device class
my @classes = ('SNMP::Info');
my @classes = ($class || 'SNMP::Info');
unless ($class) {
$snmp_args{AutoSpecify} = 1;
if ($device->snmp_class) {
unshift @classes, $device->snmp_class;
}
else {
$snmp_args{AutoSpecity} = 1;
}
my $info = undef;
@@ -148,7 +150,7 @@ sub _try_connect {
: _try_write($info, $device, $comm));
# first time a device is discovered, re-instantiate into specific class
if ($info and $info->device_type ne $class) {
if ($snmp_args->{AutoSpecify} and $info and $info->device_type ne $class) {
$class = $info->device_type;
debug
sprintf '[%s] try_connect with ver: %s, new class: %s, comm: %s',