Additional debug levels for netdisco-do to show DBIx::Class and net-snmp

This commit is contained in:
Oliver Gorwits
2014-08-04 23:39:33 +01:00
parent 06ba99e4e6
commit 770a92a772
3 changed files with 56 additions and 13 deletions

View File

@@ -5,6 +5,7 @@
* [#108] Port Bounce port control feature (down and up in succession) * [#108] Port Bounce port control feature (down and up in succession)
* Support for stuffing other locations into @INC at runtime * Support for stuffing other locations into @INC at runtime
* New netdisco-do command "show" for diagnostic reporting * New netdisco-do command "show" for diagnostic reporting
* Additional debug levels for netdisco-do to show DBIx::Class and net-snmp
[ENHANCEMENTS] [ENHANCEMENTS]

View File

@@ -45,12 +45,12 @@ use Pod::Usage;
use Getopt::Long; use Getopt::Long;
Getopt::Long::Configure ("bundling"); Getopt::Long::Configure ("bundling");
my ($device, $port, $extra, $debug); my ($device, $port, $extra, $debug) = (undef, undef, undef, 0);
my $result = GetOptions( my $result = GetOptions(
'device|d=s' => \$device, 'device|d=s' => \$device,
'port|p=s' => \$port, 'port|p=s' => \$port,
'extra|e=s' => \$extra, 'extra|e=s' => \$extra,
'debug|D' => \$debug, 'debug|D+' => \$debug,
) or pod2usage( ) or pod2usage(
-msg => 'error: bad options', -msg => 'error: bad options',
-verbose => 0, -verbose => 0,
@@ -61,6 +61,13 @@ my $CONFIG = config();
$CONFIG->{logger} = 'console'; $CONFIG->{logger} = 'console';
$CONFIG->{log} = ($debug ? 'debug' : 'info'); $CONFIG->{log} = ($debug ? 'debug' : 'info');
$ENV{INFO_TRACE} = 1 if $debug > 1;
$ENV{DBIC_TRACE} = 1 if $debug > 2; $ENV{DBIC_TRACE_PROFILE} = 'console';
$ENV{SNMP_TRACE} = 1 if $debug > 3;
$ENV{INFO_TRACE} = 2 if $debug > 4;
$ENV{SNMP_TRACE} = 2 if $debug > 5;
$ENV{SNMP_TRACE} = 3 if $debug > 6;
# reconfigure logging to force console output # reconfigure logging to force console output
Dancer::Logger->init('console', $CONFIG); Dancer::Logger->init('console', $CONFIG);
@@ -167,7 +174,7 @@ netdisco-do - Run any Netdisco job from the command-line.
~/bin/netdisco-do <action> [-D] [-d <device> [-p <port>] [-e <extra>]] ~/bin/netdisco-do <action> [-D] [-d <device> [-p <port>] [-e <extra>]]
Regardless of Netdisco configuration, debug level logging is enabled if the Regardless of Netdisco configuration, debug level logging is enabled if the
C<-D> flag is given. C<-D> flag is given (up to seven times).
=head1 DESCRIPTION =head1 DESCRIPTION
@@ -239,4 +246,41 @@ C<-p> parameter (port), and C<-e> parameter (VLAN number).
Set the PoE on/off status on a device port. Requires the C<-d> parameter Set the PoE on/off status on a device port. Requires the C<-d> parameter
(device), C<-p> parameter (port), and C<-e> parameter ("true" or "false"). (device), C<-p> parameter (port), and C<-e> parameter ("true" or "false").
=head1 DEBUG LEVELS
The debug flag "C<-D>" can be specified up to seven times, and enables the
following items in order:
=over 4
=item 1
Netdisco debug log level
=item 2
L<SNMP::Info> logging
=item 3
L<DBIx::Class> logging
=item 4
L<SNMP> (net-snmp) logging
=item 5
Even more L<SNMP::Info> logging
=item 6
Even more L<SNMP> (net-snmp) logging
=item 7
Even more than more L<SNMP> (net-snmp) logging
=back
=cut =cut

View File

@@ -57,7 +57,7 @@ Returns C<undef> if the connection fails.
sub snmp_connect_rw { _snmp_connect_generic('write', @_) } sub snmp_connect_rw { _snmp_connect_generic('write', @_) }
sub _snmp_connect_generic { sub _snmp_connect_generic {
my ($mode, $ip, $class) = @_; my ($mode, $ip, $useclass) = @_;
$mode ||= 'read'; $mode ||= 'read';
# get device details from db # get device details from db
@@ -102,12 +102,9 @@ sub _snmp_connect_generic {
: (reverse (1 .. (setting('snmpver') || 3))) ); : (reverse (1 .. (setting('snmpver') || 3))) );
# use existing or new device class # use existing or new device class
my @classes = ($class || 'SNMP::Info'); my @classes = ($useclass || 'SNMP::Info');
unless ($class) { if ($device->snmp_class and not $useclass) {
$snmp_args{AutoSpecify} = 1; unshift @classes, $device->snmp_class;
if ($device->snmp_class) {
unshift @classes, $device->snmp_class;
}
} }
my $info = undef; my $info = undef;
@@ -124,7 +121,8 @@ sub _snmp_connect_generic {
next unless $class; next unless $class;
my %local_args = (%snmp_args, Version => $ver); my %local_args = (%snmp_args, Version => $ver);
$info = _try_connect($device, $class, $comm, $mode, \%local_args); $info = _try_connect($device, $class, $comm, $mode, \%local_args,
($useclass ? 0 : 1) );
last COMMUNITY if $info; last COMMUNITY if $info;
} }
} }
@@ -134,7 +132,7 @@ sub _snmp_connect_generic {
} }
sub _try_connect { sub _try_connect {
my ($device, $class, $comm, $mode, $snmp_args) = @_; my ($device, $class, $comm, $mode, $snmp_args, $reclass) = @_;
my %comm_args = _mk_info_commargs($comm); my %comm_args = _mk_info_commargs($comm);
my $debug_comm = ( $comm->{community} my $debug_comm = ( $comm->{community}
? $ENV{SHOW_COMMUNITY} ? $comm->{community} : '<hidden>' ? $ENV{SHOW_COMMUNITY} ? $comm->{community} : '<hidden>'
@@ -152,7 +150,7 @@ sub _try_connect {
: _try_write($info, $device, $comm)); : _try_write($info, $device, $comm));
# first time a device is discovered, re-instantiate into specific class # first time a device is discovered, re-instantiate into specific class
if ($snmp_args->{AutoSpecify} and $info and $info->device_type ne $class) { if ($reclass and $info and $info->device_type ne $class) {
$class = $info->device_type; $class = $info->device_type;
debug debug
sprintf '[%s] try_connect with ver: %s, new class: %s, comm: %s', sprintf '[%s] try_connect with ver: %s, new class: %s, comm: %s',