Additional debug levels for netdisco-do to show DBIx::Class and net-snmp
This commit is contained in:
@@ -5,6 +5,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
|
||||
* Additional debug levels for netdisco-do to show DBIx::Class and net-snmp
|
||||
|
||||
[ENHANCEMENTS]
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ use Pod::Usage;
|
||||
use Getopt::Long;
|
||||
Getopt::Long::Configure ("bundling");
|
||||
|
||||
my ($device, $port, $extra, $debug);
|
||||
my ($device, $port, $extra, $debug) = (undef, undef, undef, 0);
|
||||
my $result = GetOptions(
|
||||
'device|d=s' => \$device,
|
||||
'port|p=s' => \$port,
|
||||
'extra|e=s' => \$extra,
|
||||
'debug|D' => \$debug,
|
||||
'debug|D+' => \$debug,
|
||||
) or pod2usage(
|
||||
-msg => 'error: bad options',
|
||||
-verbose => 0,
|
||||
@@ -61,6 +61,13 @@ my $CONFIG = config();
|
||||
$CONFIG->{logger} = 'console';
|
||||
$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
|
||||
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>]]
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
(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
|
||||
|
||||
@@ -57,7 +57,7 @@ Returns C<undef> if the connection fails.
|
||||
sub snmp_connect_rw { _snmp_connect_generic('write', @_) }
|
||||
|
||||
sub _snmp_connect_generic {
|
||||
my ($mode, $ip, $class) = @_;
|
||||
my ($mode, $ip, $useclass) = @_;
|
||||
$mode ||= 'read';
|
||||
|
||||
# get device details from db
|
||||
@@ -102,12 +102,9 @@ sub _snmp_connect_generic {
|
||||
: (reverse (1 .. (setting('snmpver') || 3))) );
|
||||
|
||||
# use existing or new device class
|
||||
my @classes = ($class || 'SNMP::Info');
|
||||
unless ($class) {
|
||||
$snmp_args{AutoSpecify} = 1;
|
||||
if ($device->snmp_class) {
|
||||
unshift @classes, $device->snmp_class;
|
||||
}
|
||||
my @classes = ($useclass || 'SNMP::Info');
|
||||
if ($device->snmp_class and not $useclass) {
|
||||
unshift @classes, $device->snmp_class;
|
||||
}
|
||||
|
||||
my $info = undef;
|
||||
@@ -124,7 +121,8 @@ sub _snmp_connect_generic {
|
||||
next unless $class;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -134,7 +132,7 @@ sub _snmp_connect_generic {
|
||||
}
|
||||
|
||||
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 $debug_comm = ( $comm->{community}
|
||||
? $ENV{SHOW_COMMUNITY} ? $comm->{community} : '<hidden>'
|
||||
@@ -152,7 +150,7 @@ sub _try_connect {
|
||||
: _try_write($info, $device, $comm));
|
||||
|
||||
# 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;
|
||||
debug
|
||||
sprintf '[%s] try_connect with ver: %s, new class: %s, comm: %s',
|
||||
|
||||
Reference in New Issue
Block a user