diff --git a/bin/netdisco-sshcollector b/bin/netdisco-sshcollector index 48d97306..04b66052 100755 --- a/bin/netdisco-sshcollector +++ b/bin/netdisco-sshcollector @@ -53,10 +53,13 @@ use Pod::Usage 'pod2usage'; use Getopt::Long; Getopt::Long::Configure ("bundling"); -my ($debug, $sqltrace) = (undef, 0); +my ($debug, $sqltrace, $device, $opensshdebug, $workers) = (undef, 0, undef, undef, "auto"); my $result = GetOptions( - 'debug|D' => \$debug, - 'sqltrace|Q+' => \$sqltrace, + 'debug|D' => \$debug, + 'sqltrace|Q' => \$sqltrace, + 'device|d=s' => \$device, + 'opensshdebug|O' => \$opensshdebug, + 'workers|w=i' => \$workers, ) or pod2usage( -msg => 'error: bad options', -verbose => 0, @@ -71,10 +74,11 @@ $ENV{DBIC_TRACE} ||= $sqltrace; # reconfigure logging to force console output Dancer::Logger->init('console', $CONFIG); -#this may be helpful with SSH issues: -#$Net::OpenSSH::debug = ~0; +if ($opensshdebug){ + $Net::OpenSSH::debug = ~0; +} -MCE::Loop::init { chunk_size => 1 }; +MCE::Loop::init { chunk_size => 1, max_workers => $workers }; my %stats; $stats{entry} = 0; @@ -83,6 +87,11 @@ exit main(); sub main { my @input = @{ setting('sshcollector') }; + if ($device){ + @input = grep{ ($_->{hostname} && $_->{hostname} eq $device) + || ($_->{ip} && $_->{ip} eq $device) } @input; + } + #one-line Fisher-Yates from https://www.perlmonks.org/index.pl?node=Array%20One-Liners my ($i,$j) = (0); @input[-$i,$j] = @input[$j,-$i] while $j = rand(@input - $i), ++$i < @input; @@ -108,7 +117,12 @@ sub main { ], ); - MCE->gather( process($hostlabel, $ssh, $host) ); + + if ($ssh->error){ + warning "WARNING: Couldn't connect to <$hostlabel> - " . $ssh->error; + }else{ + MCE->gather( process($hostlabel, $ssh, $host) ); + } } } \@input; @@ -173,7 +187,10 @@ full SNMP support ~/bin/localenv cpanm --notest Net::OpenSSH Expect # run manually, or add to cron: - ~/bin/netdisco-sshcollector [-DQ] + ~/bin/netdisco-sshcollector [-DQO] [-w ] + + # limit run to a single device defined in the config + ~/bin/netdisco-sshcollector [-DQO] [-w ] -d =head1 DESCRIPTION @@ -271,10 +288,7 @@ don't support command execution via ssh: The returned IP and MAC addresses should be in a format that the respective B and B datatypes in PostgreSQL can handle. -=head1 DEBUG LEVELS - -The flags "C<-DQ>" can be specified, multiple times, and enable the following -items in order: +=head1 COMMAND LINE OPTIONS =over 4 @@ -284,7 +298,21 @@ Netdisco debug log level =item C<-Q> -L trace enabled +L trace enabled. + +=item C<-O> + +L trace enabled + +=item C<-w> + +Set maximum parallel workers for L. The default is B. + +=item C<-d device> + +Only run for a single device. Takes an IP or hostname, must exactly match the value +in the config file. + =back