diff --git a/Changes b/Changes index 7e5b48bc..e5d57d74 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,19 @@ +2.042002 - 2019-03-20 + + [ENHANCEMENTS] + + * allow pseudo devices to arpnip + + [BUG FIXES] + + * the store worker phase will return more accurate status + +2.042001 - 2019-03-18 + + [BUG FIXES] + + * Do not clobber sshcollector config + 2.042000 - 2019-03-17 [NEW FEATURES] diff --git a/MANIFEST b/MANIFEST index f241ae23..c762ec84 100644 --- a/MANIFEST +++ b/MANIFEST @@ -369,6 +369,7 @@ share/schema_versions/App-Netdisco-DB-51-52-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-52-53-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-53-54-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-54-55-PostgreSQL.sql +share/schema_versions/App-Netdisco-DB-55-56-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-6-7-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-7-8-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-8-9-PostgreSQL.sql diff --git a/META.json b/META.json index 49e06809..9d198b2a 100644 --- a/META.json +++ b/META.json @@ -120,7 +120,7 @@ "provides" : { "App::Netdisco" : { "file" : "lib/App/Netdisco.pm", - "version" : "2.042000" + "version" : "2.042002" }, "App::Netdisco::AnyEvent::Nbtstat" : { "file" : "lib/App/Netdisco/AnyEvent/Nbtstat.pm" @@ -142,7 +142,7 @@ }, "App::Netdisco::DB" : { "file" : "lib/App/Netdisco/DB.pm", - "version" : "55" + "version" : "56" }, "App::Netdisco::DB::ExplicitLocking" : { "file" : "lib/App/Netdisco/DB/ExplicitLocking.pm" @@ -814,6 +814,6 @@ "x_IRC" : "irc://irc.freenode.org/#netdisco", "x_MailingList" : "https://lists.sourceforge.net/lists/listinfo/netdisco-users" }, - "version" : "2.042000", + "version" : "2.042002", "x_serialization_backend" : "JSON::PP version 2.97001" } diff --git a/META.yml b/META.yml index 5f33dadb..63e248fa 100644 --- a/META.yml +++ b/META.yml @@ -23,7 +23,7 @@ name: App-Netdisco provides: App::Netdisco: file: lib/App/Netdisco.pm - version: '2.042000' + version: '2.042002' App::Netdisco::AnyEvent::Nbtstat: file: lib/App/Netdisco/AnyEvent/Nbtstat.pm App::Netdisco::Backend::Job: @@ -38,7 +38,7 @@ provides: file: lib/App/Netdisco/Configuration.pm App::Netdisco::DB: file: lib/App/Netdisco/DB.pm - version: '55' + version: '56' App::Netdisco::DB::ExplicitLocking: file: lib/App/Netdisco/DB/ExplicitLocking.pm App::Netdisco::DB::Result::Admin: @@ -559,5 +559,5 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/BSD-3-Clause repository: https://github.com/netdisco/netdisco -version: '2.042000' +version: '2.042002' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/bin/netdisco-sshcollector b/bin/netdisco-sshcollector index 0f42f7c0..aaa52000 100755 --- a/bin/netdisco-sshcollector +++ b/bin/netdisco-sshcollector @@ -181,8 +181,21 @@ sub store_arpentries { =head1 NAME -netdisco-sshcollector - Collect ARP data for Netdisco from devices without -full SNMP support +netdisco-sshcollector - DEPRECATED! + +=head1 DEPRECATION NOTICE + +The functionality of this standalone script has been incorporated into Netdisco core. + +Please read the deprecation notice if you are using C: + +=over 4 + +=item * + +https://github.com/netdisco/netdisco/wiki/sshcollector-Deprecation + +=back =head1 SYNOPSIS diff --git a/lib/App/Netdisco.pm b/lib/App/Netdisco.pm index 58ed9967..89f03eba 100644 --- a/lib/App/Netdisco.pm +++ b/lib/App/Netdisco.pm @@ -4,7 +4,7 @@ use strict; use warnings; use 5.010_000; -our $VERSION = '2.042000'; +our $VERSION = '2.042002'; use App::Netdisco::Configuration; =head1 NAME diff --git a/lib/App/Netdisco/Backend/Job.pm b/lib/App/Netdisco/Backend/Job.pm index ea28c258..75879326 100644 --- a/lib/App/Netdisco/Backend/Job.pm +++ b/lib/App/Netdisco/Backend/Job.pm @@ -81,14 +81,35 @@ sub cancel { return Status->error($msg); } +=head2 best_status + +Find the best status so far. The process is to track back from the last worker +and find the highest scoring status, skipping the check phase. + +=cut + +sub best_status { + my $job = shift; + my $cur_level = 0; + my $cur_status = ''; + + foreach my $status (reverse @{ $job->_statuslist }) { + next if $status->phase + and $status->phase !~ m/^(?:early|main|store|late)$/; + + if ($status->level >= $cur_level) { + $cur_level = $status->level; + $cur_status = $status->status; + } + } + + return $cur_status; +} + =head2 finalise_status Find the best status and log it into the job's C and C slots. -The process is to track back from the last worker and find the best status, -which is C in early or main phases, or else any status in any non-user -phase. - =cut sub finalise_status { diff --git a/lib/App/Netdisco/DB.pm b/lib/App/Netdisco/DB.pm index e5dad2c9..74074f95 100644 --- a/lib/App/Netdisco/DB.pm +++ b/lib/App/Netdisco/DB.pm @@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces( ); our # try to hide from kwalitee - $VERSION = 55; # schema version used for upgrades, keep as integer + $VERSION = 56; # schema version used for upgrades, keep as integer use Path::Class; use File::ShareDir 'dist_dir'; diff --git a/lib/App/Netdisco/Util/DeviceAuth.pm b/lib/App/Netdisco/Util/DeviceAuth.pm index 9c4f4c11..8c68f714 100644 --- a/lib/App/Netdisco/Util/DeviceAuth.pm +++ b/lib/App/Netdisco/Util/DeviceAuth.pm @@ -3,6 +3,7 @@ package App::Netdisco::Util::DeviceAuth; use Dancer qw/:syntax :script/; use App::Netdisco::Util::DNS 'hostname_from_ip'; +use Storable 'dclone'; use Try::Tiny; use base 'Exporter'; @@ -67,8 +68,8 @@ sub fixup_device_auth { } # import legacy sshcollector configuration - my $sshcollector = (setting('sshcollector') || []); - foreach my $stanza (@$sshcollector) { + my @sshcollector = @{ dclone (setting('sshcollector') || []) }; + foreach my $stanza (@sshcollector) { # defaults $stanza->{driver} = 'cli'; $stanza->{read} = 1; diff --git a/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm b/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm index fc60c47e..bf4b9d38 100644 --- a/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm +++ b/lib/App/Netdisco/Web/Plugin/AdminTask/PseudoDevice.pm @@ -36,6 +36,7 @@ ajax '/ajax/control/admin/pseudodevice/add' => require_role admin => sub { ip => param('ip'), dns => param('dns'), vendor => 'netdisco', + layers => '00000100', last_discover => \'now()', }); return unless $device; diff --git a/lib/App/Netdisco/Worker/Plugin/Arpnip.pm b/lib/App/Netdisco/Worker/Plugin/Arpnip.pm index 1d79f128..12e8f1e3 100644 --- a/lib/App/Netdisco/Worker/Plugin/Arpnip.pm +++ b/lib/App/Netdisco/Worker/Plugin/Arpnip.pm @@ -16,13 +16,10 @@ register_worker({ phase => 'check' }, sub { return Status->error("arpnip skipped: $device not yet discovered") unless $device->in_storage; - return Status->defer("arpnip skipped: $device is pseudo-device") - if $device->is_pseudo; - - return Status->defer("arpnip skipped: $device has no layer 3 capability") + return Status->info("arpnip skipped: $device has no layer 3 capability") unless $device->has_layer(3); - return Status->defer("arpnip deferred: $device is not arpnipable") + return Status->info("arpnip skipped: $device is not arpnipable") unless is_arpnipable_now($device); return Status->done('arpnip is able to run'); diff --git a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm index 50af14c6..b6122f35 100644 --- a/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Arpnip/Nodes.pm @@ -35,7 +35,9 @@ register_worker({ phase => 'store' }, sub { $device->ip, scalar @{ vars->{'v6arps'} }; $device->update({last_arpnip => \$now}); - return Status->done("Ended arpnip for $device"); + + my $status = $job->best_status; + return Status->$status("Ended arpnip for $device"); }); register_worker({ phase => 'main', driver => 'snmp' }, sub { @@ -53,7 +55,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { push @{ vars->{'v6arps'} }, @{get_arps_snmp($device, $snmp->ipv6_n2p_mac, $snmp->ipv6_n2p_addr) }; - return Status->info("Gathered arp caches from $device"); + return Status->done("Gathered arp caches from $device"); }); # get an arp table (v4 or v6) @@ -97,7 +99,7 @@ register_worker({ phase => 'main', driver => 'cli' }, sub { push @{ vars->{'v6arps'} }, grep { NetAddr::IP::Lite->new($_->{ip})->bits == 128 } @arps; - return Status->info("Gathered arp caches from $device"); + return Status->done("Gathered arp caches from $device"); }); sub get_arps_cli { diff --git a/lib/App/Netdisco/Worker/Plugin/Arpwalk.pm b/lib/App/Netdisco/Worker/Plugin/Arpwalk.pm index 599aba4c..a7a21837 100644 --- a/lib/App/Netdisco/Worker/Plugin/Arpwalk.pm +++ b/lib/App/Netdisco/Worker/Plugin/Arpwalk.pm @@ -11,9 +11,8 @@ register_worker({ phase => 'main' }, sub { my ($job, $workerconf) = @_; my %queued = map {$_ => 1} jq_queued('arpnip'); - my @devices = schema('netdisco')->resultset('Device')->search({ - -or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }], - })->has_layer('3')->get_column('ip')->all; + my @devices = schema('netdisco')->resultset('Device') + ->has_layer('3')->get_column('ip')->all; my @filtered_devices = grep {!exists $queued{$_}} @devices; jq_insert([ diff --git a/lib/App/Netdisco/Worker/Plugin/Discover.pm b/lib/App/Netdisco/Worker/Plugin/Discover.pm index 7c25daeb..d65d274e 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover.pm @@ -16,7 +16,7 @@ register_worker({ phase => 'check' }, sub { return Status->error("discover failed: no device param (need -d ?)") if $device->ip eq '0.0.0.0'; - return Status->defer("discover skipped: $device is pseudo-device") + return Status->info("discover skipped: $device is pseudo-device") if $device->is_pseudo; # runner has already called get_device to promote $job->device @@ -24,7 +24,7 @@ register_worker({ phase => 'check' }, sub { if $device->in_storage and ($job->subaction eq 'with-nodes' and not $job->username); - return Status->defer("discover deferred: $device is not discoverable") + return Status->info("discover skipped: $device is not discoverable") unless is_discoverable_now($device); return Status->done('Discover is able to run.'); diff --git a/lib/App/Netdisco/Worker/Plugin/Macsuck.pm b/lib/App/Netdisco/Worker/Plugin/Macsuck.pm index 163bf7e4..8f90fdf0 100644 --- a/lib/App/Netdisco/Worker/Plugin/Macsuck.pm +++ b/lib/App/Netdisco/Worker/Plugin/Macsuck.pm @@ -16,13 +16,13 @@ register_worker({ phase => 'check' }, sub { return Status->error("macsuck skipped: $device not yet discovered") unless $device->in_storage; - return Status->defer("macsuck skipped: $device is pseudo-device") + return Status->info("macsuck skipped: $device is pseudo-device") if $device->is_pseudo; - return Status->defer("macsuck skipped: $device has no layer 2 capability") + return Status->info("macsuck skipped: $device has no layer 2 capability") unless $device->has_layer(2); - return Status->defer("macsuck deferred: $device is not macsuckable") + return Status->info("macsuck skipped: $device is not macsuckable") unless is_macsuckable_now($device); return Status->done('Macsuck is able to run.'); diff --git a/lib/App/Netdisco/Worker/Plugin/Nbtstat.pm b/lib/App/Netdisco/Worker/Plugin/Nbtstat.pm index cff91e92..66734de8 100644 --- a/lib/App/Netdisco/Worker/Plugin/Nbtstat.pm +++ b/lib/App/Netdisco/Worker/Plugin/Nbtstat.pm @@ -12,7 +12,7 @@ register_worker({ phase => 'check' }, sub { return Status->error('nbtstat failed: unable to interpret device param') unless defined $job->device; - return Status->defer(sprintf 'nbtstat deferred: %s is not macsuckable', $job->device->ip) + return Status->info(sprintf 'nbtstat skipped: %s is not macsuckable', $job->device->ip) unless is_macsuckable($job->device); return Status->done('Nbtstat is able to run.'); diff --git a/lib/App/Netdisco/Worker/Status.pm b/lib/App/Netdisco/Worker/Status.pm index eeae6570..6da8a458 100644 --- a/lib/App/Netdisco/Worker/Status.pm +++ b/lib/App/Netdisco/Worker/Status.pm @@ -97,8 +97,9 @@ A numeric constant for the status, to allow comparison. sub level { my $self = shift; return (($self->status eq 'done') ? 4 - : ($self->status eq 'info') ? 3 - : ($self->status eq 'defer') ? 2 : 1); + : ($self->status eq 'defer') ? 3 + : ($self->status eq 'info') ? 2 + : ($self->status eq 'error') ? 1 : 0); } 1; diff --git a/share/schema_versions/App-Netdisco-DB-55-56-PostgreSQL.sql b/share/schema_versions/App-Netdisco-DB-55-56-PostgreSQL.sql new file mode 100644 index 00000000..d7ca523f --- /dev/null +++ b/share/schema_versions/App-Netdisco-DB-55-56-PostgreSQL.sql @@ -0,0 +1,5 @@ +BEGIN; + +UPDATE device SET layers = '00000100' WHERE vendor = 'netdisco'; + +COMMIT;