From 3f211650b89e58c80d862632faf6c9529c6f8b27 Mon Sep 17 00:00:00 2001 From: nick n <39005454+inphobia@users.noreply.github.com> Date: Fri, 1 Mar 2019 12:34:42 +0100 Subject: [PATCH 01/33] last pieces for db schema upgrade last piece of #510 --- MANIFEST | 1 + META.json | 4 ++-- META.yml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MANIFEST b/MANIFEST index 338458ca..32b20851 100644 --- a/MANIFEST +++ b/MANIFEST @@ -364,6 +364,7 @@ share/schema_versions/App-Netdisco-DB-5-6-PostgreSQL.sql share/schema_versions/App-Netdisco-DB-50-51-PostgreSQL.sql 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-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 d25d2b90..26b7cba6 100644 --- a/META.json +++ b/META.json @@ -140,7 +140,7 @@ }, "App::Netdisco::DB" : { "file" : "lib/App/Netdisco/DB.pm", - "version" : "53" + "version" : "54" }, "App::Netdisco::DB::ExplicitLocking" : { "file" : "lib/App/Netdisco/DB/ExplicitLocking.pm" @@ -801,5 +801,5 @@ "x_MailingList" : "https://lists.sourceforge.net/lists/listinfo/netdisco-users" }, "version" : "2.040003", - "x_serialization_backend" : "JSON::PP version 2.97001" + "x_serialization_backend" : "JSON::PP version 4.02" } diff --git a/META.yml b/META.yml index 42d85541..6fd33dec 100644 --- a/META.yml +++ b/META.yml @@ -37,7 +37,7 @@ provides: file: lib/App/Netdisco/Configuration.pm App::Netdisco::DB: file: lib/App/Netdisco/DB.pm - version: '53' + version: '54' App::Netdisco::DB::ExplicitLocking: file: lib/App/Netdisco/DB/ExplicitLocking.pm App::Netdisco::DB::Result::Admin: From 77decc23b73cbcda0cd0516fdc73972cda622a0b Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 14:45:37 +0000 Subject: [PATCH 02/33] #514 inconsistent results in ip inventory (inphobia) --- lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm b/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm index 315db783..437462ae 100644 --- a/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm +++ b/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm @@ -110,7 +110,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { 'ip', 'mac', 'dns', 'time_last', 'time_first', 'active', 'node', 'age' ], - order_by => [{-asc => 'ip'}, {-desc => 'active'}], + order_by => [{-asc => 'ip'}, {-desc => 'active'}, {-asc => 'node'}], } )->as_query; From d4c7579c101d693827da2f3fad533ad725f97ba0 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 14:47:49 +0000 Subject: [PATCH 03/33] #522 TypeAhead.pm can reference empty data (inphobia) --- lib/App/Netdisco/Web/TypeAhead.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/App/Netdisco/Web/TypeAhead.pm b/lib/App/Netdisco/Web/TypeAhead.pm index 3994302e..40c7da62 100644 --- a/lib/App/Netdisco/Web/TypeAhead.pm +++ b/lib/App/Netdisco/Web/TypeAhead.pm @@ -49,7 +49,7 @@ ajax '/ajax/data/port/typeahead' => require_login sub { if $port; my $results = [ - map {{ label => (sprintf "%s (%s)", $_->port, $_->name), value => $_->port }} + map {{ label => (sprintf "%s (%s)", $_->port, ($_->name || '')), value => $_->port }} sort { &App::Netdisco::Util::Web::sort_port($a->port, $b->port) } $set->all ]; From 1265bc8470911d90c7c446c64976207c3285a151 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 14:52:21 +0000 Subject: [PATCH 04/33] #520 catch slave ports defined without a master --- lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm index 63240c3d..95d2340d 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Properties.pm @@ -238,6 +238,7 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub { # must do this after building %interfaces so that we can set is_master foreach my $sidx (keys %$agg_ports) { my $slave = $interfaces->{$sidx} or next; + next unless defined $agg_ports->{$sidx}; # slave without a master?! my $master = $interfaces->{ $agg_ports->{$sidx} } or next; next unless exists $interfaces{$slave} and exists $interfaces{$master}; From ca3fd8f466f144f76a9df6d760a5d8f34ae14621 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 15:00:18 +0000 Subject: [PATCH 05/33] #505 device renumber should update device port properties and device skips --- lib/App/Netdisco/DB/Result/Device.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/App/Netdisco/DB/Result/Device.pm b/lib/App/Netdisco/DB/Result/Device.pm index a6e06545..e7d431a7 100644 --- a/lib/App/Netdisco/DB/Result/Device.pm +++ b/lib/App/Netdisco/DB/Result/Device.pm @@ -262,20 +262,25 @@ sub renumber { foreach my $set (qw/ DeviceIp DeviceModule - DevicePower - DeviceVlan DevicePort DevicePortLog DevicePortPower + DevicePortProperties DevicePortSsid DevicePortVlan DevicePortWireless + DevicePower + DeviceVlan /) { $schema->resultset($set) ->search({ip => $old_ip}) ->update({ip => $new_ip}); } + $schema->resultset('DeviceSkip') + ->search({device => $old_ip}) + ->update({device => $new_ip}); + $schema->resultset('DevicePort') ->search({remote_ip => $old_ip}) ->update({remote_ip => $new_ip}); From 9952f0c6c723359c7c1e29abfc0dcad30a52c083 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 15:02:12 +0000 Subject: [PATCH 06/33] #499 netdisco-do renumber reports wrong ip (inphobia) --- lib/App/Netdisco/Util/Device.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/App/Netdisco/Util/Device.pm b/lib/App/Netdisco/Util/Device.pm index a6af95fa..47f4a920 100644 --- a/lib/App/Netdisco/Util/Device.pm +++ b/lib/App/Netdisco/Util/Device.pm @@ -120,7 +120,7 @@ sub renumber_device { schema('netdisco')->resultset('UserLog')->create({ username => session('logged_in_user'), userip => scalar eval {request->remote_address}, - event => (sprintf "Renumber device %s to %s", $device->ip, $new_ip), + event => (sprintf "Renumber device %s to %s", $ip, $new_ip), }); $happy = 1; From 78e30a7926dbec941860420348c917ae823146f3 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 16:28:15 +0000 Subject: [PATCH 07/33] #500 filtering in device/ports on native vlan duplicates entries --- lib/App/Netdisco/Web/Plugin/Device/Ports.pm | 57 +++++++++++---------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/App/Netdisco/Web/Plugin/Device/Ports.pm b/lib/App/Netdisco/Web/Plugin/Device/Ports.pm index b5276052..be5f98ea 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Ports.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Ports.pm @@ -25,25 +25,6 @@ get '/ajax/content/device/ports' => require_login sub { if ($f) { if (($prefer eq 'vlan') or (not $prefer and $f =~ m/^\d+$/)) { return unless $f =~ m/^\d+$/; - - if (param('invert')) { - $set = $set->search({ - 'me.vlan' => { '!=' => $f }, - 'port_vlans.vlan' => [ - '-or' => { '!=' => $f }, { '=' => undef } - ], - }, { join => 'port_vlans' }); - } - else { - $set = $set->search({ - -or => { - 'me.vlan' => $f, - 'port_vlans.vlan' => $f, - }, - }, { join => 'port_vlans' }); - } - - return unless $set->count; } else { if (param('partial')) { @@ -120,7 +101,7 @@ get '/ajax/content/device/ports' => require_login sub { # now begin to join tables depending on the selected columns/options # get vlans on the port - # leave this query dormant (lazy) unless c_vmember is set + # leave this query dormant (lazy) unless c_vmember is set or vlan filtering my $vlans = $set->search({}, { select => [ 'port', @@ -131,7 +112,7 @@ get '/ajax/content/device/ports' => require_login sub { group_by => 'me.port', }); - if (param('c_vmember')) { + if (param('c_vmember') or ($prefer eq 'vlan') or (not $prefer and $f =~ m/^\d+$/)) { $vlans = { map {( $_->port => { # DBIC smart enough to work out this should be an arrayref :) @@ -194,13 +175,37 @@ get '/ajax/content/device/ports' => require_login sub { # also get remote LLDP inventory if asked for $set = $set->with_remote_inventory if param('n_inventory'); - # sort ports (empty set would be a 'no records' msg) - my $results = [ sort { &App::Netdisco::Util::Web::sort_port($a->port, $b->port) } $set->all ]; - return unless scalar @$results; + # run query + my @results = $set->all; + + # filter for tagged vlan using existing agg query, + # which is better than join inflation + if (($prefer eq 'vlan') or (not $prefer and $f =~ m/^\d+$/)) { + if (param('invert')) { + @results = grep { + (!defined $_->vlan or $_->vlan ne $f) + and + (0 == scalar grep {defined and $_ ne $f} @{ $vlans->{$_->port}->{vlan_set} }) + } @results; + } + else { + @results = grep { + ($_->vlan eq $f) + or + (scalar grep {defined and $_ eq $f} @{ $vlans->{$_->port}->{vlan_set} }) + } @results; + } + } + + # sort ports + @results = sort { &App::Netdisco::Util::Web::sort_port($a->port, $b->port) } @results; + + # empty set would be a 'no records' msg + return unless scalar @results; if (request->is_ajax) { template 'ajax/device/ports.tt', { - results => $results, + results => \@results, nodes => $nodes_name, ips => $ips_name, device => $device, @@ -210,7 +215,7 @@ get '/ajax/content/device/ports' => require_login sub { else { header( 'Content-Type' => 'text/comma-separated-values' ); template 'ajax/device/ports_csv.tt', { - results => $results, + results => \@results, nodes => $nodes_name, ips => $ips_name, device => $device, From ce1b847ceabb3cb8ec6bac370071d55acd40dc48 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 18:47:44 +0000 Subject: [PATCH 08/33] fix bug showing no nodes when only one matches in netmap --- lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index bc1e3aec..612eebc6 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -219,8 +219,9 @@ ajax '/ajax/data/device/netmap' => require_login sub { DEVICE: while (my $device = $devices->next) { # if in neighbors or vlan mode then use %ok_dev to filter - next DEVICE if (($mapshow eq 'neighbors') or $vlan) - and (not $ok_dev{$device->ip}); + next DEVICE if ($device->ip ne $qdev->ip) + and (($mapshow eq 'neighbors') or $vlan) + and (not $ok_dev{$device->ip}); # showing only neighbors but no link # if location picked then filter next DEVICE if ((scalar @lgrplist) and ((!defined $device->location) From a1f95028caf3d59133dac0bb43fd9d26c44a9dfb Mon Sep 17 00:00:00 2001 From: nick n <39005454+inphobia@users.noreply.github.com> Date: Sat, 2 Mar 2019 19:54:22 +0100 Subject: [PATCH 09/33] catch up with changes noticed that rc-sshcollector-core received updates to changes, add them here as well. didn't mention #499 & #522 --- Changes | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Changes b/Changes index 708c7b09..477ce63f 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,20 @@ +2.04xxxx - 2019-xx-xx + + [ENHANCEMENTS] + + * #490 use new checks for ports having phones + * #494 update Cisco ASA ssh collector (stromsoe) + * #510 store ifindex in Device Port Properties table (rc9000) + + [BUG FIXES] + + * #492 Port Control uses VLAN config check (inphobia) + * #493 HTML tag fix (inphobia) + * #500 no more duplicate entries in vlan filter (ollyg) + * #505 renumbering device missed a few tables (ollyg) + * #514 ipinventory report returns consistent data (inphobia) + * #520 make sure aggports have a master<->slave (ollyg) + 2.040003 - 2019-01-18 [NEW FEATURES] From e7aacddbc615a48e5dd204b9dc32a5deadbdefea Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 20:01:05 +0000 Subject: [PATCH 10/33] #498 Map with VLAN filter omits unconnected devices --- lib/App/Netdisco/DB/ResultSet/Device.pm | 14 +++++------ .../Netdisco/Web/Plugin/Device/Neighbors.pm | 23 ++++++++----------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/App/Netdisco/DB/ResultSet/Device.pm b/lib/App/Netdisco/DB/ResultSet/Device.pm index 27e6defc..271eeda6 100644 --- a/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -47,16 +47,16 @@ sub with_times { ->search({}, { '+columns' => { - uptime_age => \("replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', " + uptime_age => \("replace(age(timestamp 'epoch' + me.uptime / 100 * interval '1 second', " ."timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')"), first_seen_stamp => \"to_char(me.creation, 'YYYY-MM-DD HH24:MI')", - last_discover_stamp => \"to_char(last_discover, 'YYYY-MM-DD HH24:MI')", - last_macsuck_stamp => \"to_char(last_macsuck, 'YYYY-MM-DD HH24:MI')", - last_arpnip_stamp => \"to_char(last_arpnip, 'YYYY-MM-DD HH24:MI')", + last_discover_stamp => \"to_char(me.last_discover, 'YYYY-MM-DD HH24:MI')", + last_macsuck_stamp => \"to_char(me.last_macsuck, 'YYYY-MM-DD HH24:MI')", + last_arpnip_stamp => \"to_char(me.last_arpnip, 'YYYY-MM-DD HH24:MI')", since_first_seen => \"extract(epoch from (age(now(), me.creation)))", - since_last_discover => \"extract(epoch from (age(now(), last_discover)))", - since_last_macsuck => \"extract(epoch from (age(now(), last_macsuck)))", - since_last_arpnip => \"extract(epoch from (age(now(), last_arpnip)))", + since_last_discover => \"extract(epoch from (age(now(), me.last_discover)))", + since_last_macsuck => \"extract(epoch from (age(now(), me.last_macsuck)))", + since_last_arpnip => \"extract(epoch from (age(now(), me.last_arpnip)))", }, }); } diff --git a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index 612eebc6..5a1624be 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -179,17 +179,6 @@ ajax '/ajax/data/device/netmap' => require_login sub { ]) : ()) }, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); - if ($vlan) { - $links = $links->search({ - -or => [ - { 'left_vlans.vlan' => $vlan }, - { 'right_vlans.vlan' => $vlan }, - ], - }, { - join => [qw/left_vlans right_vlans/], - }); - } - while (my $link = $links->next) { push @{$data{'links'}}, { FROMID => $link->{left_ip}, @@ -217,10 +206,18 @@ ajax '/ajax/data/device/netmap' => require_login sub { join => 'throughput', })->with_times; + # filter by vlan for all or neighbors only + if ($vlan) { + $devices = $devices->search( + { 'vlans.vlan' => $vlan }, + { join => 'vlans' } + ); + } + DEVICE: while (my $device = $devices->next) { - # if in neighbors or vlan mode then use %ok_dev to filter + # if in neighbors mode then use %ok_dev to filter next DEVICE if ($device->ip ne $qdev->ip) - and (($mapshow eq 'neighbors') or $vlan) + and ($mapshow eq 'neighbors') and (not $ok_dev{$device->ip}); # showing only neighbors but no link # if location picked then filter From a643820a6200a7439724158a6817f3858732050c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 21:54:27 +0000 Subject: [PATCH 11/33] #428 Port-Channels not showing in netmap --- .../Netdisco/DB/Result/Virtual/DeviceLinks.pm | 20 ++++++++++--------- .../Netdisco/Web/Plugin/Device/Neighbors.pm | 19 +++++++----------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm b/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm index a503a3ae..9d2339ca 100644 --- a/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm +++ b/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm @@ -22,8 +22,8 @@ __PACKAGE__->result_source_instance->view_definition(<result_source_instance->view_definition(<result_source_instance->view_definition(<result_source_instance->view_definition(<{left_dns} || $link->{left_name} || $link->{left_ip})) =~ s/$domain$//; (my $right_name = lc($link->{right_dns} || $link->{right_name} || $link->{right_ip})) =~ s/$domain$//; - if ($link->{aggports} == 1) { - return sprintf '%s:%s (%s)
%s:%s (%s)', - $left_name, $link->{left_port}->[0], - ($link->{left_descr}->[0] || 'no description'), - $right_name, $link->{right_port}->[0], - ($link->{right_descr}->[0] || 'no description'); - } - else { - return sprintf '%s:(%s)
%s:(%s)', - $left_name, join(',', @{$link->{left_port}}), - $right_name, join(',', @{$link->{right_port}}); - } + my @zipped = List::MoreUtils::zip6 + @{$link->{left_port}}, @{$link->{left_descr}}, + @{$link->{right_port}}, @{$link->{right_descr}}; + + return join '

', map { sprintf '%s:%s (%s)
%s:%s (%s)', + $left_name, $_->[0], ($_->[1] || 'no description'), + $right_name, $_->[2], ($_->[3] || 'no description') } @zipped; } ajax '/ajax/data/device/netmap' => require_login sub { From 7a8bcb094e4d48dd0d900d275ca5ce781ddb42ba Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 22:23:39 +0000 Subject: [PATCH 12/33] #521 Search Node Date Range not working --- .../Netdisco/Web/Plugin/Report/IpInventory.pm | 2 +- lib/App/Netdisco/Web/Plugin/Search/Node.pm | 48 ++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm b/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm index 437462ae..0fc809f0 100644 --- a/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm +++ b/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm @@ -115,7 +115,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { )->as_query; my $rs; - if ( $start && $end ) { + if ( $start and $end ) { $start = $start . ' 00:00:00'; $end = $end . ' 23:59:59'; diff --git a/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/lib/App/Netdisco/Web/Plugin/Search/Node.pm index 45394e2c..090802a5 100644 --- a/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -27,35 +27,51 @@ ajax '/ajax/content/search/node' => require_login sub { my @active = (param('archived') ? () : (-bool => 'active')); my (@times, @wifitimes, @porttimes); - if ($start and $end) { + if ( $start and $end ) { $start = $start . ' 00:00:00'; $end = $end . ' 23:59:59'; + if ($agenot) { @times = (-or => [ - time_first => [ { '<', $start }, undef ], - time_last => { '>', $end }, + time_first => [ undef ], + time_last => [ { '<', $start }, { '>', $end } ] ]); @wifitimes = (-or => [ - time_last => { '<', $start }, - time_last => { '>', $end }, + time_first => [ undef ], + time_last => [ { '<', $start }, { '>', $end } ] ]); @porttimes = (-or => [ - creation => { '<', $start }, - creation => { '>', $end }, + creation => [ undef ], + creation => [ { '<', $start }, { '>', $end } ] ]); } else { - @times = (-and => [ - time_first => { '>=', $start }, - time_last => { '<=', $end }, + @times = (-or => [ + -and => [ + time_first => undef, + time_last => undef, + ], + -and => [ + time_last => { '>=', $start }, + time_last => { '<=', $end }, + ], ]); - @wifitimes = (-and => [ - time_last => { '>=', $start }, - time_last => { '<=', $end }, + @wifitimes = (-or => [ + -and => [ + time_first => undef, + time_last => undef, + ], + -and => [ + time_last => { '>=', $start }, + time_last => { '<=', $end }, + ], ]); - @porttimes = (-and => [ - creation => { '>=', $start }, - creation => { '<=', $end }, + @porttimes = (-or => [ + creation => undef, + -and => [ + creation => { '>=', $start }, + creation => { '<=', $end }, + ], ]); } } From ef560fb59aebf4f7cf64487931d41b6f5aa83d92 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 2 Mar 2019 22:41:40 +0000 Subject: [PATCH 13/33] #506 relax device renumber so it works for an alias --- lib/App/Netdisco/DB/Result/Device.pm | 2 ++ lib/App/Netdisco/Worker/Plugin.pm | 6 +++--- lib/App/Netdisco/Worker/Plugin/Renumber.pm | 8 ++++---- lib/App/Netdisco/Worker/Runner.pm | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/App/Netdisco/DB/Result/Device.pm b/lib/App/Netdisco/DB/Result/Device.pm index e7d431a7..412ecdaa 100644 --- a/lib/App/Netdisco/DB/Result/Device.pm +++ b/lib/App/Netdisco/DB/Result/Device.pm @@ -277,6 +277,8 @@ sub renumber { ->update({ip => $new_ip}); } + $schema->resultset('DeviceSkip') + ->search({device => $new_ip})->delete; $schema->resultset('DeviceSkip') ->search({device => $old_ip}) ->update({device => $new_ip}); diff --git a/lib/App/Netdisco/Worker/Plugin.pm b/lib/App/Netdisco/Worker/Plugin.pm index 8f05a7c4..44999403 100644 --- a/lib/App/Netdisco/Worker/Plugin.pm +++ b/lib/App/Netdisco/Worker/Plugin.pm @@ -74,9 +74,9 @@ register 'register_worker' => sub { push @newuserconf, dclone $stanza; } - # per-device action but no device creds available - return $job->add_status( Status->info('skip: driver or action not applicable') ) - if 0 == scalar @newuserconf; + # # per-device action but no device creds available + # return $job->add_status( Status->info('skip: driver or action not applicable') ) + # if 0 == scalar @newuserconf; } # back up and restore device_auth diff --git a/lib/App/Netdisco/Worker/Plugin/Renumber.pm b/lib/App/Netdisco/Worker/Plugin/Renumber.pm index c3b815ba..e768002e 100644 --- a/lib/App/Netdisco/Worker/Plugin/Renumber.pm +++ b/lib/App/Netdisco/Worker/Plugin/Renumber.pm @@ -28,10 +28,10 @@ register_worker({ phase => 'main' }, sub { my $old_ip = $device->ip; my $new_ip = NetAddr::IP->new($extra); - my $new_dev = get_device($new_ip->addr); - if ($new_dev and $new_dev->in_storage and ($new_dev->ip ne $device->ip)) { - return Status->error(sprintf "Already know new device as: %s.", $new_dev->ip); - } + #my $new_dev = get_device($new_ip->addr); + #if ($new_dev and $new_dev->in_storage and ($new_dev->ip ne $device->ip)) { + # return Status->error(sprintf "Already know new device as: %s.", $new_dev->ip); + #} renumber_device($device, $new_ip); return Status->done(sprintf 'Renumbered device %s to %s (%s).', diff --git a/lib/App/Netdisco/Worker/Runner.pm b/lib/App/Netdisco/Worker/Runner.pm index 193281ca..4cdbf041 100644 --- a/lib/App/Netdisco/Worker/Runner.pm +++ b/lib/App/Netdisco/Worker/Runner.pm @@ -49,9 +49,9 @@ sub run { push @newuserconf, dclone $stanza; } - # per-device action but no device creds available - return $job->add_status( Status->defer('deferred job with no device creds') ) - if 0 == scalar @newuserconf; + # # per-device action but no device creds available + # return $job->add_status( Status->defer('deferred job with no device creds') ) + # if 0 == scalar @newuserconf; } # back up and restore device_auth From 57cb6ddb707b938b8a5c0d39a52b9e4c8a8892da Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 09:19:39 +0000 Subject: [PATCH 14/33] fix for over-eager fix to #506 --- lib/App/Netdisco/Worker/Plugin/Renumber.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/App/Netdisco/Worker/Plugin/Renumber.pm b/lib/App/Netdisco/Worker/Plugin/Renumber.pm index e768002e..c3b815ba 100644 --- a/lib/App/Netdisco/Worker/Plugin/Renumber.pm +++ b/lib/App/Netdisco/Worker/Plugin/Renumber.pm @@ -28,10 +28,10 @@ register_worker({ phase => 'main' }, sub { my $old_ip = $device->ip; my $new_ip = NetAddr::IP->new($extra); - #my $new_dev = get_device($new_ip->addr); - #if ($new_dev and $new_dev->in_storage and ($new_dev->ip ne $device->ip)) { - # return Status->error(sprintf "Already know new device as: %s.", $new_dev->ip); - #} + my $new_dev = get_device($new_ip->addr); + if ($new_dev and $new_dev->in_storage and ($new_dev->ip ne $device->ip)) { + return Status->error(sprintf "Already know new device as: %s.", $new_dev->ip); + } renumber_device($device, $new_ip); return Status->done(sprintf 'Renumbered device %s to %s (%s).', From 2bae91f1b669e2901ebcb59696fdaa562c0396b7 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 12:01:34 +0000 Subject: [PATCH 15/33] rename match_devicetype() to match_to_setting() --- lib/App/Netdisco/Util/Device.pm | 8 ++++---- lib/App/Netdisco/Web/Device.pm | 4 ++-- .../Netdisco/Worker/Plugin/Discover/PortProperties.pm | 10 +++++----- lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/App/Netdisco/Util/Device.pm b/lib/App/Netdisco/Util/Device.pm index 47f4a920..d14b7a7d 100644 --- a/lib/App/Netdisco/Util/Device.pm +++ b/lib/App/Netdisco/Util/Device.pm @@ -10,7 +10,7 @@ our @EXPORT_OK = qw/ get_device delete_device renumber_device - match_devicetype + match_to_setting is_discoverable is_discoverable_now is_arpnipable is_arpnipable_now is_macsuckable is_macsuckable_now @@ -129,7 +129,7 @@ sub renumber_device { return $happy; } -=head2 match_devicetype( $type, $setting_name ) +=head2 match_to_setting( $type, $setting_name ) Given a C<$type> (which may be any text value), returns true if any of the list of regular expressions in C<$setting_name> is matched, otherwise returns @@ -137,7 +137,7 @@ false. =cut -sub match_devicetype { +sub match_to_setting { my ($type, $setting_name) = @_; return 0 unless $type and $setting_name; return (scalar grep {$type =~ m/$_/} @@ -165,7 +165,7 @@ sub is_discoverable { my ($ip, $remote_type) = @_; my $device = get_device($ip) or return 0; - if (match_devicetype($remote_type, 'discover_no_type')) { + if (match_to_setting($remote_type, 'discover_no_type')) { return _bail_msg("is_discoverable: $device matched discover_no_type"); } diff --git a/lib/App/Netdisco/Web/Device.pm b/lib/App/Netdisco/Web/Device.pm index e4cfdd00..010ed550 100644 --- a/lib/App/Netdisco/Web/Device.pm +++ b/lib/App/Netdisco/Web/Device.pm @@ -7,7 +7,7 @@ use Dancer::Plugin::Auth::Extensible; use URI (); use URL::Encode 'url_params_mixed'; -use App::Netdisco::Util::Device 'match_devicetype'; +use App::Netdisco::Util::Device 'match_to_setting'; # build view settings for port connected nodes and devices set('connected_properties' => [ @@ -20,7 +20,7 @@ hook 'before_template' => sub { my $tokens = shift; # allow checking of discoverability of remote connected device - $tokens->{has_snmp} = sub { not match_devicetype(shift, 'discover_no_type') }; + $tokens->{has_snmp} = sub { not match_to_setting(shift, 'discover_no_type') }; my $defaults = var('sidebar_defaults')->{'device_ports'} or return; diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/PortProperties.pm b/lib/App/Netdisco/Worker/Plugin/Discover/PortProperties.pm index 8b492021..5803cc6c 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/PortProperties.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/PortProperties.pm @@ -8,7 +8,7 @@ use App::Netdisco::Transport::SNMP (); use Dancer::Plugin::DBIC 'schema'; use Encode; -use App::Netdisco::Util::Device 'match_devicetype'; +use App::Netdisco::Util::Device 'match_to_setting'; register_worker({ phase => 'main', driver => 'snmp' }, sub { my ($job, $workerconf) = @_; @@ -86,12 +86,12 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { my $remote_type = Encode::decode('UTF-8', $c_platform->{$idx} || ''); $properties{ $port }->{remote_is_wap} = 'true' - if scalar grep {match_devicetype($_, 'wap_capabilities')} @$remote_cap - or match_devicetype($remote_type, 'wap_platforms'); + if scalar grep {match_to_setting($_, 'wap_capabilities')} @$remote_cap + or match_to_setting($remote_type, 'wap_platforms'); $properties{ $port }->{remote_is_phone} = 'true' - if scalar grep {match_devicetype($_, 'phone_capabilities')} @$remote_cap - or match_devicetype($remote_type, 'phone_platforms'); + if scalar grep {match_to_setting($_, 'phone_capabilities')} @$remote_cap + or match_to_setting($remote_type, 'phone_platforms'); next unless scalar grep {defined && m/^inventory$/} @{ $rem_media_cap->{$idx} }; diff --git a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm index 0b150d1c..9ea9dfb9 100644 --- a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm @@ -7,7 +7,7 @@ use aliased 'App::Netdisco::Worker::Status'; use App::Netdisco::Transport::SNMP (); use App::Netdisco::Util::Permission 'check_acl_no'; use App::Netdisco::Util::PortMAC 'get_port_macs'; -use App::Netdisco::Util::Device 'match_devicetype'; +use App::Netdisco::Util::Device 'match_to_setting'; use App::Netdisco::Util::Node 'check_mac'; use App::Netdisco::Util::SNMP 'snmp_comm_reindex'; use Dancer::Plugin::DBIC 'schema'; @@ -342,7 +342,7 @@ sub walk_fwtable { # neighbors otherwise it would kill the DB with device lookups. my $neigh_cannot_macsuck = eval { # can fail check_acl_no(($device_port->neighbor || "0 but true"), 'macsuck_unsupported') || - match_devicetype($device_port->remote_type, 'macsuck_unsupported_type') }; + match_to_setting($device_port->remote_type, 'macsuck_unsupported_type') }; if ($device_port->is_uplink) { if ($neigh_cannot_macsuck) { From 09d29954d211ad1e6c1911fb4d43df8980a00bae Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 12:26:50 +0000 Subject: [PATCH 16/33] #512 fix regression in phone/wap discovery exclusion --- lib/App/Netdisco/Util/Device.pm | 16 +++++++++++----- share/config.yml | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/App/Netdisco/Util/Device.pm b/lib/App/Netdisco/Util/Device.pm index d14b7a7d..8707fde4 100644 --- a/lib/App/Netdisco/Util/Device.pm +++ b/lib/App/Netdisco/Util/Device.pm @@ -154,8 +154,9 @@ the local configuration to discover the device. The configuration items C and C are checked against the given IP. -If C<$device_type> is also given, then C will also be -checked. +If C<$device_type> is also given, then C will be checked. +Also respects C and C if either are set to +false. Returns false if the host is not permitted to discover the target device. @@ -165,9 +166,14 @@ sub is_discoverable { my ($ip, $remote_type) = @_; my $device = get_device($ip) or return 0; - if (match_to_setting($remote_type, 'discover_no_type')) { - return _bail_msg("is_discoverable: $device matched discover_no_type"); - } + return _bail_msg("is_discoverable: $device matches wap_platforms but discover_waps is not enabled") + if (match_to_setting($remote_type, 'wap_platforms') and not setting('discover_waps')); + + return _bail_msg("is_discoverable: $device matches phone_platforms but discover_phones is not enabled") + if (match_to_setting($remote_type, 'phone_platforms') and not setting('discover_phones')); + + return _bail_msg("is_discoverable: $device matched discover_no_type") + if (match_to_setting($remote_type, 'discover_no_type')); return _bail_msg("is_discoverable: $device matched discover_no") if check_acl_no($device, 'discover_no'); diff --git a/share/config.yml b/share/config.yml index be6950f2..24b31d66 100644 --- a/share/config.yml +++ b/share/config.yml @@ -229,9 +229,9 @@ devices_no: [] devices_only: [] discover_no: [] discover_only: [] -discover_no_type: - - '(?i)phone' - - '(?i)(?:wap|wireless)' +discover_no_type: [] +discover_waps: true +discover_phones: false discover_min_age: 0 macsuck_no: [] macsuck_only: [] From 9c956466f3bf2e799412fef5b61966fb2878bc49 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 12:32:07 +0000 Subject: [PATCH 17/33] also update default config for new discover_phones and discover_waps settings --- share/environments/deployment.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/share/environments/deployment.yml b/share/environments/deployment.yml index cd792907..a1147c97 100644 --- a/share/environments/deployment.yml +++ b/share/environments/deployment.yml @@ -39,20 +39,18 @@ device_auth: # ¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸ +# +# SOME MORE INTERESTING SETTINGS WHERE THE DEFAULTS ARE PROBABLY OKAY +# # ¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸ -# --------------------------------------------------------------- -# OTHER INTERESTING SETTINGS WHERE THE DEFAULTS ARE PROBABLY OKAY -# --------------------------------------------------------------- - -# do not discover IP Phones or Wireless Access Points. +# discover Wireless Access Points, but not IP Phones # usually these are visible as device neighbors but don't support # SNMP, which just clogs up the job queue. # ``````````````````````````````````````````````````````````````` -#discover_no_type: -# - '(?i)phone' -# - '(?i)(?:wap|wireless)' +#discover_waps: true +#disover_phones: false # this is the schedule for automatically keeping netdisco up-to-date; # these are good defaults, so only uncomment if needing to change. From 189d234b55c01b8e7def428bed9c4be35022ea59 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 12:47:38 +0000 Subject: [PATCH 18/33] check discover_no_type and friends earlier on in neighbors list build --- .../Worker/Plugin/Discover/Neighbors.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm index 6a64b8ee..afda0133 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm @@ -45,7 +45,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { # only enqueue if device is not already discovered, # discover_* config permits the discovery foreach my $neighbor (@to_discover) { - my ($ip, $remote_type, $remote_id) = @$neighbor; + my ($ip, $remote_id) = @$neighbor; if ($seen_ip{ $ip }++) { debug sprintf ' queue - skip: IP %s is already queued from %s', @@ -63,13 +63,6 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub { my $newdev = get_device($ip); next if $newdev->in_storage; - if (not is_discoverable($newdev, $remote_type)) { - debug sprintf - ' queue - skip: %s of type [%s] excluded by discover_* config', - $ip, ($remote_type || ''); - next; - } - # risk of things going wrong...? # https://quickview.cloudapps.cisco.com/quickview/bug/CSCur12254 @@ -246,7 +239,15 @@ sub store_neighbors { # what we came here to do.... discover the neighbor debug sprintf ' [%s] neigh - %s with ID [%s] on %s', $device->ip, $remote_ip, ($remote_id || ''), $port; - push @to_discover, [$remote_ip, $remote_type, $remote_id]; + + if (is_discoverable($remote_ip, $remote_type)) { + push @to_discover, [$remote_ip, $remote_id]; + } + else { + debug sprintf + ' [%s] neigh - skip: %s of type [%s] excluded by discover_* config', + $device->ip, $remote_ip, ($remote_type || ''); + } $remote_port = $c_port->{$entry}; if (defined $remote_port) { From b83e614c851beafd68d131999698023c5380338c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 13:00:36 +0000 Subject: [PATCH 19/33] make discover_{phones,waps} work with LLDP capabilities as well --- lib/App/Netdisco/Util/Device.pm | 14 ++++++++++---- .../Netdisco/Worker/Plugin/Discover/Neighbors.pm | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/App/Netdisco/Util/Device.pm b/lib/App/Netdisco/Util/Device.pm index 8707fde4..e0fbd211 100644 --- a/lib/App/Netdisco/Util/Device.pm +++ b/lib/App/Netdisco/Util/Device.pm @@ -146,7 +146,7 @@ sub match_to_setting { sub _bail_msg { debug $_[0]; return 0; } -=head2 is_discoverable( $ip, $device_type? ) +=head2 is_discoverable( $ip, [$device_type, \@device_capabilities]? ) Given an IP address, returns C if Netdisco on this host is permitted by the local configuration to discover the device. @@ -163,14 +163,20 @@ Returns false if the host is not permitted to discover the target device. =cut sub is_discoverable { - my ($ip, $remote_type) = @_; + my ($ip, $remote_type, $remote_cap) = @_; my $device = get_device($ip) or return 0; + $remote_type ||= ''; + $remote_cap ||= []; return _bail_msg("is_discoverable: $device matches wap_platforms but discover_waps is not enabled") - if (match_to_setting($remote_type, 'wap_platforms') and not setting('discover_waps')); + if ((not setting('discover_waps')) and + (match_to_setting($remote_type, 'wap_platforms') or + scalar grep {match_to_setting($_, 'wap_capabilities')} @$remote_cap)); return _bail_msg("is_discoverable: $device matches phone_platforms but discover_phones is not enabled") - if (match_to_setting($remote_type, 'phone_platforms') and not setting('discover_phones')); + if ((not setting('discover_phones')) and + (match_to_setting($remote_type, 'phone_platforms') or + scalar grep {match_to_setting($_, 'phone_capabilities')} @$remote_cap)); return _bail_msg("is_discoverable: $device matched discover_no_type") if (match_to_setting($remote_type, 'discover_no_type')); diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm index afda0133..6489ee43 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm @@ -169,6 +169,7 @@ sub store_neighbors { my $remote_port = undef; my $remote_type = Encode::decode('UTF-8', $c_platform->{$entry} || ''); my $remote_id = Encode::decode('UTF-8', $c_id->{$entry}); + my $remote_cap = $c_cap->{$entry} || []; next unless $remote_ip; my $r_netaddr = NetAddr::IP::Lite->new($remote_ip); @@ -240,7 +241,7 @@ sub store_neighbors { debug sprintf ' [%s] neigh - %s with ID [%s] on %s', $device->ip, $remote_ip, ($remote_id || ''), $port; - if (is_discoverable($remote_ip, $remote_type)) { + if (is_discoverable($remote_ip, $remote_type, $remote_cap)) { push @to_discover, [$remote_ip, $remote_id]; } else { From ac381e080235b2efc0878b4ccfaa5c2d6901b2ff Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 14:13:20 +0000 Subject: [PATCH 20/33] #506 was a red herring --- lib/App/Netdisco/Worker/Plugin.pm | 6 +++--- lib/App/Netdisco/Worker/Runner.pm | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/App/Netdisco/Worker/Plugin.pm b/lib/App/Netdisco/Worker/Plugin.pm index 44999403..8f05a7c4 100644 --- a/lib/App/Netdisco/Worker/Plugin.pm +++ b/lib/App/Netdisco/Worker/Plugin.pm @@ -74,9 +74,9 @@ register 'register_worker' => sub { push @newuserconf, dclone $stanza; } - # # per-device action but no device creds available - # return $job->add_status( Status->info('skip: driver or action not applicable') ) - # if 0 == scalar @newuserconf; + # per-device action but no device creds available + return $job->add_status( Status->info('skip: driver or action not applicable') ) + if 0 == scalar @newuserconf; } # back up and restore device_auth diff --git a/lib/App/Netdisco/Worker/Runner.pm b/lib/App/Netdisco/Worker/Runner.pm index 4cdbf041..193281ca 100644 --- a/lib/App/Netdisco/Worker/Runner.pm +++ b/lib/App/Netdisco/Worker/Runner.pm @@ -49,9 +49,9 @@ sub run { push @newuserconf, dclone $stanza; } - # # per-device action but no device creds available - # return $job->add_status( Status->defer('deferred job with no device creds') ) - # if 0 == scalar @newuserconf; + # per-device action but no device creds available + return $job->add_status( Status->defer('deferred job with no device creds') ) + if 0 == scalar @newuserconf; } # back up and restore device_auth From 6cdfd80d10975c22a9aa2050a02e2ed45dbad3c6 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 14:34:00 +0000 Subject: [PATCH 21/33] allow undiscovered neighbors report to use discover_{waps,phones} setting --- lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm | 6 ++++++ .../Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm b/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm index 1fe1c1d5..4cde1ffc 100644 --- a/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm +++ b/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm @@ -15,6 +15,7 @@ __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL'); d.ip, d.name, d.dns, p.port, p.name AS port_description, p.remote_ip, p.remote_id, p.remote_type, p.remote_port, + dpp.remote_is_wap, dpp.remote_is_phone, l.log AS comment, a.log, a.finished @@ -23,6 +24,7 @@ __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL'); INNER JOIN device d USING (ip) LEFT OUTER JOIN device_skip ds ON ('discover' = ANY(ds.actionset) AND p.remote_ip = ds.device) + LEFT OUTER JOIN device_port_properties dpp USING (ip, port) LEFT OUTER JOIN device_port_log l USING (ip, port) LEFT OUTER JOIN admin a ON (p.remote_ip = a.device AND a.action = 'discover') @@ -58,6 +60,10 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "remote_id", { data_type => "text", is_nullable => 1 }, + "remote_is_wap", + { data_type => "boolean", is_nullable => 1 }, + "remote_is_phone", + { data_type => "boolean", is_nullable => 1 }, "comment", { data_type => "text", is_nullable => 1 }, "log", diff --git a/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm b/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm index d409d3cb..293d2525 100644 --- a/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm @@ -27,6 +27,8 @@ get '/ajax/content/admin/undiscoveredneighbors' => require_role admin => sub { # create a new row object to avoid hitting the DB in get_device() my $dev = schema('netdisco')->resultset('Device')->new({ip => $r->{remote_ip}}); next unless is_discoverable( $dev, $r->{remote_type} ); + next if (not setting('discover_waps')) and $r->{remote_is_wap}; + next if (not setting('discover_phones')) and $r->{remote_is_phone}; push @discoverable_results, $r; } return unless scalar @discoverable_results; From e9efc45182f590ea94ddd2928e8156162d022b0d Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 3 Mar 2019 14:56:48 +0000 Subject: [PATCH 22/33] release 2.040004 --- Build.PL | 2 +- Changes | 19 +++++++++++++++---- META.json | 8 ++++---- META.yml | 6 +++--- lib/App/Netdisco.pm | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Build.PL b/Build.PL index ded87058..8b2de830 100644 --- a/Build.PL +++ b/Build.PL @@ -72,7 +72,7 @@ Module::Build->new( 'Starman' => '0.4008', 'Storable' => '0', 'Sys::SigAction' => '0', - 'SNMP::Info' => '3.64', + 'SNMP::Info' => '3.65', 'SQL::Abstract' => '1.85', 'SQL::Translator' => '0.11024', 'Template' => '2.24', diff --git a/Changes b/Changes index 477ce63f..33075ea6 100644 --- a/Changes +++ b/Changes @@ -1,19 +1,30 @@ -2.04xxxx - 2019-xx-xx +2.040004 - 2019-03-03 + + [NEW FEATURES] + + * #510 store ifindex in Device Port Properties table (rc9000) + * new discover_waps and discover_phones boolean settings (ollyg) [ENHANCEMENTS] - * #490 use new checks for ports having phones + * #428 Port-Channels now showing in netmap (ollyg) + * #490 use new LLDP capability checks for ports having phones (ollyg) * #494 update Cisco ASA ssh collector (stromsoe) - * #510 store ifindex in Device Port Properties table (rc9000) [BUG FIXES] - * #492 Port Control uses VLAN config check (inphobia) + * #492 Port Control incorrectly uses VLAN config check (inphobia) * #493 HTML tag fix (inphobia) + * #498 Map with VLAN filter omits unconnected devices (ollyg) + * #499 netdisco-do renumber reports wrong ip (inphobia) * #500 no more duplicate entries in vlan filter (ollyg) * #505 renumbering device missed a few tables (ollyg) + * #512 fix regression in phone/wap discovery exclusion (ollyg) * #514 ipinventory report returns consistent data (inphobia) * #520 make sure aggports have a master<->slave (ollyg) + * #521 Search Node Date Range not working (ollyg) + * #522 TypeAhead.pm can reference empty data (inphobia) + * fix bug showing no nodes when only one matches in netmap (ollyg) 2.040003 - 2019-01-18 diff --git a/META.json b/META.json index 26b7cba6..a3532e86 100644 --- a/META.json +++ b/META.json @@ -81,7 +81,7 @@ "Plack::Middleware::ReverseProxy" : "0.15", "Pod::Usage" : "0", "Role::Tiny" : "1.002005", - "SNMP::Info" : "3.64", + "SNMP::Info" : "3.65", "SQL::Abstract" : "1.85", "SQL::Translator" : "0.11024", "Scope::Guard" : "0", @@ -118,7 +118,7 @@ "provides" : { "App::Netdisco" : { "file" : "lib/App/Netdisco.pm", - "version" : "2.040003" + "version" : "2.040004" }, "App::Netdisco::AnyEvent::Nbtstat" : { "file" : "lib/App/Netdisco/AnyEvent/Nbtstat.pm" @@ -800,6 +800,6 @@ "x_IRC" : "irc://irc.freenode.org/#netdisco", "x_MailingList" : "https://lists.sourceforge.net/lists/listinfo/netdisco-users" }, - "version" : "2.040003", - "x_serialization_backend" : "JSON::PP version 4.02" + "version" : "2.040004", + "x_serialization_backend" : "JSON::PP version 2.97001" } diff --git a/META.yml b/META.yml index 6fd33dec..ea2fba17 100644 --- a/META.yml +++ b/META.yml @@ -22,7 +22,7 @@ name: App-Netdisco provides: App::Netdisco: file: lib/App/Netdisco.pm - version: '2.040003' + version: '2.040004' App::Netdisco::AnyEvent::Nbtstat: file: lib/App/Netdisco/AnyEvent/Nbtstat.pm App::Netdisco::Backend::Job: @@ -518,7 +518,7 @@ requires: Plack::Middleware::ReverseProxy: '0.15' Pod::Usage: '0' Role::Tiny: '1.002005' - SNMP::Info: '3.64' + SNMP::Info: '3.65' SQL::Abstract: '1.85' SQL::Translator: '0.11024' Scope::Guard: '0' @@ -549,5 +549,5 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/bsd-license.php repository: https://github.com/netdisco/netdisco -version: '2.040003' +version: '2.040004' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/lib/App/Netdisco.pm b/lib/App/Netdisco.pm index d88cdab0..2e47b040 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.040003'; +our $VERSION = '2.040004'; use App::Netdisco::Configuration; =head1 NAME From 0c98318a4508d9c91a8d1182b38e556454f9c9fa Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 4 Mar 2019 09:57:18 +0000 Subject: [PATCH 23/33] #526 fix discover syntax bug --- lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm index 6489ee43..a546a58d 100644 --- a/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm +++ b/lib/App/Netdisco/Worker/Plugin/Discover/Neighbors.pm @@ -120,6 +120,7 @@ sub store_neighbors { my $c_port = $snmp->c_port; my $c_id = $snmp->c_id; my $c_platform = $snmp->c_platform; + my $c_cap = $snmp->c_cap; # cache the device ports to save hitting the database for many single rows vars->{'device_ports'} = From 6e7de3fff3719720da72db76801c9e2e45b5be78 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 4 Mar 2019 09:59:41 +0000 Subject: [PATCH 24/33] release 2.040005 --- Changes | 6 ++++++ META.json | 4 ++-- META.yml | 4 ++-- lib/App/Netdisco.pm | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 33075ea6..3bc8d770 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +2.040005 - 2019-03-04 + + [BUG FIXES] + + * #526 fix discover syntax bug + 2.040004 - 2019-03-03 [NEW FEATURES] diff --git a/META.json b/META.json index a3532e86..8bcef558 100644 --- a/META.json +++ b/META.json @@ -118,7 +118,7 @@ "provides" : { "App::Netdisco" : { "file" : "lib/App/Netdisco.pm", - "version" : "2.040004" + "version" : "2.040005" }, "App::Netdisco::AnyEvent::Nbtstat" : { "file" : "lib/App/Netdisco/AnyEvent/Nbtstat.pm" @@ -800,6 +800,6 @@ "x_IRC" : "irc://irc.freenode.org/#netdisco", "x_MailingList" : "https://lists.sourceforge.net/lists/listinfo/netdisco-users" }, - "version" : "2.040004", + "version" : "2.040005", "x_serialization_backend" : "JSON::PP version 2.97001" } diff --git a/META.yml b/META.yml index ea2fba17..0d493cfe 100644 --- a/META.yml +++ b/META.yml @@ -22,7 +22,7 @@ name: App-Netdisco provides: App::Netdisco: file: lib/App/Netdisco.pm - version: '2.040004' + version: '2.040005' App::Netdisco::AnyEvent::Nbtstat: file: lib/App/Netdisco/AnyEvent/Nbtstat.pm App::Netdisco::Backend::Job: @@ -549,5 +549,5 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/bsd-license.php repository: https://github.com/netdisco/netdisco -version: '2.040004' +version: '2.040005' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/lib/App/Netdisco.pm b/lib/App/Netdisco.pm index 2e47b040..c30f8700 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.040004'; +our $VERSION = '2.040005'; use App::Netdisco::Configuration; =head1 NAME From e09dab53622960bee715d9d423ed2dee91b2e36c Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 4 Mar 2019 11:39:12 +0000 Subject: [PATCH 25/33] #527 update List::MoreUtils version requirement --- Build.PL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build.PL b/Build.PL index 8b2de830..3d7fdeb6 100644 --- a/Build.PL +++ b/Build.PL @@ -46,7 +46,7 @@ Module::Build->new( 'JSON' => '2.90', 'JSON::XS' => '3.01', 'List::Util' => '1.49', - 'List::MoreUtils' => '0.33', + 'List::MoreUtils' => '0.428', 'MIME::Base64' => '3.13', 'Module::Load' => '0.32', 'Moo' => '1.001000', From 48857ae3002536b469acb678292981377b960b65 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 4 Mar 2019 12:03:31 +0000 Subject: [PATCH 26/33] release 2.040006 --- Changes | 6 ++++++ META.json | 6 +++--- META.yml | 6 +++--- lib/App/Netdisco.pm | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Changes b/Changes index 3bc8d770..f8a2cb73 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +2.040006 - 2019-03-04 + + [BUG FIXES] + + * #527 update List::MoreUtils version requirement + 2.040005 - 2019-03-04 [BUG FIXES] diff --git a/META.json b/META.json index 8bcef558..5b18dc40 100644 --- a/META.json +++ b/META.json @@ -60,7 +60,7 @@ "IO::Socket::SSL" : "2.048", "JSON" : "2.90", "JSON::XS" : "3.01", - "List::MoreUtils" : "0.33", + "List::MoreUtils" : "0.428", "List::Util" : "1.49", "MCE" : "1.703", "MIME::Base64" : "3.13", @@ -118,7 +118,7 @@ "provides" : { "App::Netdisco" : { "file" : "lib/App/Netdisco.pm", - "version" : "2.040005" + "version" : "2.040006" }, "App::Netdisco::AnyEvent::Nbtstat" : { "file" : "lib/App/Netdisco/AnyEvent/Nbtstat.pm" @@ -800,6 +800,6 @@ "x_IRC" : "irc://irc.freenode.org/#netdisco", "x_MailingList" : "https://lists.sourceforge.net/lists/listinfo/netdisco-users" }, - "version" : "2.040005", + "version" : "2.040006", "x_serialization_backend" : "JSON::PP version 2.97001" } diff --git a/META.yml b/META.yml index 0d493cfe..a5071bc5 100644 --- a/META.yml +++ b/META.yml @@ -22,7 +22,7 @@ name: App-Netdisco provides: App::Netdisco: file: lib/App/Netdisco.pm - version: '2.040005' + version: '2.040006' App::Netdisco::AnyEvent::Nbtstat: file: lib/App/Netdisco/AnyEvent/Nbtstat.pm App::Netdisco::Backend::Job: @@ -497,7 +497,7 @@ requires: IO::Socket::SSL: '2.048' JSON: '2.90' JSON::XS: '3.01' - List::MoreUtils: '0.33' + List::MoreUtils: '0.428' List::Util: '1.49' MCE: '1.703' MIME::Base64: '3.13' @@ -549,5 +549,5 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/bsd-license.php repository: https://github.com/netdisco/netdisco -version: '2.040005' +version: '2.040006' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/lib/App/Netdisco.pm b/lib/App/Netdisco.pm index c30f8700..bca470bc 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.040005'; +our $VERSION = '2.040006'; use App::Netdisco::Configuration; =head1 NAME From e3af64df77613b98c5efde9d5e7381ab0f5de52d Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 6 Mar 2019 18:42:47 +0000 Subject: [PATCH 27/33] #521-redux fix wifi date search --- Changes | 6 ++++++ lib/App/Netdisco/Web/Plugin/Search/Node.pm | 9 +++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index f8a2cb73..4f29f214 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,9 @@ +2.040007 - 2019-03-06 + + [BUG FIXES] + + * #521-redux Search Node Date Range not working (ollyg) + 2.040006 - 2019-03-04 [BUG FIXES] diff --git a/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/lib/App/Netdisco/Web/Plugin/Search/Node.pm index 090802a5..6b74c86d 100644 --- a/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -37,8 +37,8 @@ ajax '/ajax/content/search/node' => require_login sub { time_last => [ { '<', $start }, { '>', $end } ] ]); @wifitimes = (-or => [ - time_first => [ undef ], - time_last => [ { '<', $start }, { '>', $end } ] + time_last => [ undef ], + time_last => [ { '<', $start }, { '>', $end } ], ]); @porttimes = (-or => [ creation => [ undef ], @@ -57,10 +57,7 @@ ajax '/ajax/content/search/node' => require_login sub { ], ]); @wifitimes = (-or => [ - -and => [ - time_first => undef, - time_last => undef, - ], + time_last => undef, -and => [ time_last => { '>=', $start }, time_last => { '<=', $end }, From 249f05165fd25bdd43802a95c523f0486fc013de Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 6 Mar 2019 18:43:31 +0000 Subject: [PATCH 28/33] release 2.040007 --- META.json | 4 ++-- META.yml | 4 ++-- lib/App/Netdisco.pm | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/META.json b/META.json index 5b18dc40..c19aca81 100644 --- a/META.json +++ b/META.json @@ -118,7 +118,7 @@ "provides" : { "App::Netdisco" : { "file" : "lib/App/Netdisco.pm", - "version" : "2.040006" + "version" : "2.040007" }, "App::Netdisco::AnyEvent::Nbtstat" : { "file" : "lib/App/Netdisco/AnyEvent/Nbtstat.pm" @@ -800,6 +800,6 @@ "x_IRC" : "irc://irc.freenode.org/#netdisco", "x_MailingList" : "https://lists.sourceforge.net/lists/listinfo/netdisco-users" }, - "version" : "2.040006", + "version" : "2.040007", "x_serialization_backend" : "JSON::PP version 2.97001" } diff --git a/META.yml b/META.yml index a5071bc5..f7cb0c94 100644 --- a/META.yml +++ b/META.yml @@ -22,7 +22,7 @@ name: App-Netdisco provides: App::Netdisco: file: lib/App/Netdisco.pm - version: '2.040006' + version: '2.040007' App::Netdisco::AnyEvent::Nbtstat: file: lib/App/Netdisco/AnyEvent/Nbtstat.pm App::Netdisco::Backend::Job: @@ -549,5 +549,5 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/bsd-license.php repository: https://github.com/netdisco/netdisco -version: '2.040006' +version: '2.040007' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/lib/App/Netdisco.pm b/lib/App/Netdisco.pm index bca470bc..cecfe6ae 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.040006'; +our $VERSION = '2.040007'; use App::Netdisco::Configuration; =head1 NAME From fdafbb735e3beb018ccc80a4aeb0bf477ff3dc5e Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 11 Mar 2019 17:39:53 +0000 Subject: [PATCH 29/33] test compilation of all scripts and modules passes --- Build.PL | 1 + xt/00-compile.t | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 xt/00-compile.t diff --git a/Build.PL b/Build.PL index 3d7fdeb6..fe0e4bba 100644 --- a/Build.PL +++ b/Build.PL @@ -96,6 +96,7 @@ Module::Build->new( test_requires => { 'Test::More' => '1.302083', 'Env::Path' => '0', + 'Test::Compile' => '0', 'Test::File::ShareDir::Dist' => '0', }, script_files => [ diff --git a/xt/00-compile.t b/xt/00-compile.t new file mode 100644 index 00000000..307058af --- /dev/null +++ b/xt/00-compile.t @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +BEGIN { + use FindBin; + FindBin::again(); + + use Path::Class; + + # stuff useful locations into @INC and $PATH + unshift @INC, + dir($FindBin::RealBin)->parent->subdir('lib')->stringify, + dir($FindBin::RealBin, 'lib')->stringify; +} + +# for netdisco app config +use App::Netdisco; +use Test::Compile; + +my $test = Test::Compile->new(); + +my @plfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pl_files(); +my @pmfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pm_files(); + +$test->ok($test->pl_file_compiles($_), "$_ compiles") for @plfiles; +$test->ok($test->pm_file_compiles($_), "$_ compiles") for @pmfiles; + +$test->done_testing(); From 15c132a094215fe919e9d45ae3e7fea25e0dac34 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 11 Mar 2019 17:49:13 +0000 Subject: [PATCH 30/33] Revert "test compilation of all scripts and modules passes" This reverts commit fdafbb735e3beb018ccc80a4aeb0bf477ff3dc5e. --- Build.PL | 1 - xt/00-compile.t | 30 ------------------------------ 2 files changed, 31 deletions(-) delete mode 100644 xt/00-compile.t diff --git a/Build.PL b/Build.PL index fe0e4bba..3d7fdeb6 100644 --- a/Build.PL +++ b/Build.PL @@ -96,7 +96,6 @@ Module::Build->new( test_requires => { 'Test::More' => '1.302083', 'Env::Path' => '0', - 'Test::Compile' => '0', 'Test::File::ShareDir::Dist' => '0', }, script_files => [ diff --git a/xt/00-compile.t b/xt/00-compile.t deleted file mode 100644 index 307058af..00000000 --- a/xt/00-compile.t +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; - -BEGIN { - use FindBin; - FindBin::again(); - - use Path::Class; - - # stuff useful locations into @INC and $PATH - unshift @INC, - dir($FindBin::RealBin)->parent->subdir('lib')->stringify, - dir($FindBin::RealBin, 'lib')->stringify; -} - -# for netdisco app config -use App::Netdisco; -use Test::Compile; - -my $test = Test::Compile->new(); - -my @plfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pl_files(); -my @pmfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pm_files(); - -$test->ok($test->pl_file_compiles($_), "$_ compiles") for @plfiles; -$test->ok($test->pm_file_compiles($_), "$_ compiles") for @pmfiles; - -$test->done_testing(); From a1383251753bee9962770cdb90c1443b64257067 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 11 Mar 2019 21:34:18 +0000 Subject: [PATCH 31/33] travis test all branches --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index af946ef6..31f15896 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,10 @@ addons: - phantomjs hosts: - localhost -branches: - only: - - /^2\.\d{6}$/ - - 'master' +#branches: +# only: +# - /^2\.\d{6}$/ +# - 'master' install: true script: | perl Build.PL && \ From 65f695410e7b4dea2a451d04c37a9234edc300b6 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 12 Mar 2019 13:02:35 +0000 Subject: [PATCH 32/33] test compilation of all scripts and modules (#537) * test compilation of all scripts and modules passes * try adding NetSNMP::default_store * try adding NetSNMP::default_store * travis test all branches * make Configuration.pm safe for tests * remove dep * try adding net-snmp * dist: xenial * try building Net-SNMP locally * no need for Try::Tiny * allow test to pass for DPP:p * better testing setup for session cookies * yay! working compile tests for ALL! --- .travis.yml | 11 +++---- Build.PL | 1 + lib/App/Netdisco/Web.pm | 10 +++++-- lib/App/Netdisco/Worker/Plugin/DumpConfig.pm | 3 +- xt/00-compile.t | 30 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 xt/00-compile.t diff --git a/.travis.yml b/.travis.yml index 31f15896..297e8260 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,12 @@ addons: - phantomjs hosts: - localhost -#branches: -# only: -# - /^2\.\d{6}$/ -# - 'master' -install: true +branches: + only: + - /^2\.\d{6}$/ + - 'master' +install: + - cpanm --quiet --notest PkgConfig Test::CChecker Alien::zlib::Static Alien::OpenSSL::Static Alien::SNMP script: | perl Build.PL && \ ./Build && \ diff --git a/Build.PL b/Build.PL index 3d7fdeb6..fe0e4bba 100644 --- a/Build.PL +++ b/Build.PL @@ -96,6 +96,7 @@ Module::Build->new( test_requires => { 'Test::More' => '1.302083', 'Env::Path' => '0', + 'Test::Compile' => '0', 'Test::File::ShareDir::Dist' => '0', }, script_files => [ diff --git a/lib/App/Netdisco/Web.pm b/lib/App/Netdisco/Web.pm index 901eee0d..d95d1025 100644 --- a/lib/App/Netdisco/Web.pm +++ b/lib/App/Netdisco/Web.pm @@ -66,9 +66,13 @@ if (setting('template_paths') and ref [] eq ref setting('template_paths')) { # load cookie key from database setting('session_cookie_key' => undef); -my $sessions = schema('netdisco')->resultset('Session'); -my $skey = $sessions->find({id => 'dancer_session_cookie_key'}); -setting('session_cookie_key' => $skey->get_column('a_session')) if $skey; +setting('session_cookie_key' => 'this_is_for_testing_only') + if $ENV{HARNESS_ACTIVE}; +eval { + my $sessions = schema('netdisco')->resultset('Session'); + my $skey = $sessions->find({id => 'dancer_session_cookie_key'}); + setting('session_cookie_key' => $skey->get_column('a_session')) if $skey; +}; Dancer::Session::Cookie::init(session); # workaround for https://github.com/PerlDancer/Dancer/issues/935 diff --git a/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm b/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm index 3c57288a..d37e07a4 100644 --- a/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm +++ b/lib/App/Netdisco/Worker/Plugin/DumpConfig.pm @@ -11,7 +11,8 @@ register_worker({ phase => 'main' }, sub { my $extra = $job->extra; my $config = config(); - p ($extra ? $config->{$extra} : $config); + my $dump = ($extra ? $config->{$extra} : $config); + p $dump; return Status->done('Dumped config'); }); diff --git a/xt/00-compile.t b/xt/00-compile.t new file mode 100644 index 00000000..307058af --- /dev/null +++ b/xt/00-compile.t @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +BEGIN { + use FindBin; + FindBin::again(); + + use Path::Class; + + # stuff useful locations into @INC and $PATH + unshift @INC, + dir($FindBin::RealBin)->parent->subdir('lib')->stringify, + dir($FindBin::RealBin, 'lib')->stringify; +} + +# for netdisco app config +use App::Netdisco; +use Test::Compile; + +my $test = Test::Compile->new(); + +my @plfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pl_files(); +my @pmfiles = grep {$_ !~ m/(?:sshcollector|graph)/i} $test->all_pm_files(); + +$test->ok($test->pl_file_compiles($_), "$_ compiles") for @plfiles; +$test->ok($test->pm_file_compiles($_), "$_ compiles") for @pmfiles; + +$test->done_testing(); From b9218d91c8f3cb17ce1a106386ec7f71dcdc3744 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 12 Mar 2019 13:13:06 +0000 Subject: [PATCH 33/33] Support for external command to provide device_auth stanza (#532) * separate out generic device auth to DeviceAuth module * change config name to get_credentials * add debug lines and tested --- lib/App/Netdisco/Configuration.pm | 5 +- lib/App/Netdisco/Util/DeviceAuth.pm | 163 ++++++++++++++++++++++++++++ lib/App/Netdisco/Util/SNMP.pm | 116 +------------------- share/config.yml | 2 +- 4 files changed, 170 insertions(+), 116 deletions(-) create mode 100644 lib/App/Netdisco/Util/DeviceAuth.pm diff --git a/lib/App/Netdisco/Configuration.pm b/lib/App/Netdisco/Configuration.pm index 90cdc5ac..9ddd1d0f 100644 --- a/lib/App/Netdisco/Configuration.pm +++ b/lib/App/Netdisco/Configuration.pm @@ -1,7 +1,7 @@ package App::Netdisco::Configuration; use App::Netdisco::Environment; -use App::Netdisco::Util::SNMP (); +use App::Netdisco::Util::DeviceAuth (); use Dancer ':script'; use Path::Class 'dir'; @@ -84,7 +84,8 @@ if ((setting('snmp_auth') and 0 == scalar @{ setting('snmp_auth') }) config->{'community_rw'} = [ @{setting('community_rw')}, 'private' ]; } # fix up device_auth (or create it from old snmp_auth and community settings) -config->{'device_auth'} = [ App::Netdisco::Util::SNMP::fixup_device_auth() ]; +config->{'device_auth'} + = [ App::Netdisco::Util::DeviceAuth::fixup_device_auth() ]; # defaults for workers setting('workers')->{queue} ||= 'PostgreSQL'; diff --git a/lib/App/Netdisco/Util/DeviceAuth.pm b/lib/App/Netdisco/Util/DeviceAuth.pm new file mode 100644 index 00000000..bb7f79f5 --- /dev/null +++ b/lib/App/Netdisco/Util/DeviceAuth.pm @@ -0,0 +1,163 @@ +package App::Netdisco::Util::DeviceAuth; + +use Dancer qw/:syntax :script/; +use App::Netdisco::Util::DNS 'hostname_from_ip'; + +use Try::Tiny; + +use base 'Exporter'; +our @EXPORT = (); +our @EXPORT_OK = qw/ + fixup_device_auth get_external_credentials +/; +our %EXPORT_TAGS = (all => \@EXPORT_OK); + +=head1 NAME + +App::Netdisco::Util::DeviceAuth + +=head1 DESCRIPTION + +Helper functions for device authentication. + +There are no default exports, however the C<:all> tag will export all +subroutines. + +=head1 EXPORT_OK + +=head2 fixup_device_auth + +Rebuilds the C config with missing defaults and other fixups for +config changes over time. Returns a list which can replace C. + +=cut + +sub fixup_device_auth { + my $config = (setting('snmp_auth') || setting('device_auth')); + my @new_stanzas = (); + + # new style snmp config + foreach my $stanza (@$config) { + # user tagged + my $tag = ''; + if (1 == scalar keys %$stanza) { + $tag = (keys %$stanza)[0]; + $stanza = $stanza->{$tag}; + + # corner case: untagged lone community + if ($tag eq 'community') { + $tag = $stanza; + $stanza = {community => $tag}; + } + } + + # defaults + $stanza->{tag} ||= $tag; + $stanza->{read} = 1 if !exists $stanza->{read}; + $stanza->{no} ||= []; + $stanza->{only} ||= ['any']; + + die "error: config: snmpv2 community in device_auth must be single item, not list\n" + if ref $stanza->{community}; + + die "error: config: stanza in device_auth must have a tag\n" + if not $stanza->{tag} and exists $stanza->{user}; + + push @new_stanzas, $stanza + } + + # legacy config + # note: read strings tried before write + # note: read-write is no longer used for read operations + + push @new_stanzas, map {{ + read => 1, write => 0, + no => [], only => ['any'], + community => $_, + }} @{setting('community') || []}; + + push @new_stanzas, map {{ + write => 1, read => 0, + no => [], only => ['any'], + community => $_, + }} @{setting('community_rw') || []}; + + foreach my $stanza (@new_stanzas) { + $stanza->{driver} ||= 'snmp' + if exists $stanza->{community} + or exists $stanza->{user}; + } + + return @new_stanzas; +} + +=head2 get_external_credentials( $device, $mode ) + +Runs a command to gather SNMP credentials or a C stanza. + +Mode can be C or C and defaults to 'read'. + +=cut + +sub get_external_credentials { + my ($device, $mode) = @_; + my $cmd = (setting('get_credentials') || setting('get_community')); + my $ip = $device->ip; + my $host = ($device->dns || hostname_from_ip($ip) || $ip); + $mode ||= 'read'; + + if (defined $cmd and length $cmd) { + # replace variables + $cmd =~ s/\%MODE\%/$mode/egi; + $cmd =~ s/\%HOST\%/$host/egi; + $cmd =~ s/\%IP\%/$ip/egi; + + my $result = `$cmd`; # BACKTICKS + return () unless defined $result and length $result; + + my @lines = split (m/\n/, $result); + foreach my $line (@lines) { + if ($line =~ m/^community\s*=\s*(.*)\s*$/i) { + if (length $1 and $mode eq 'read') { + debug sprintf '[%s] external read credentials added', + $device->ip; + + return map {{ + read => 1, + only => [$device->ip], + community => $_, + }} split(m/\s*,\s*/,$1); + } + } + elsif ($line =~ m/^setCommunity\s*=\s*(.*)\s*$/i) { + if (length $1 and $mode eq 'write') { + debug sprintf '[%s] external write credentials added', + $device->ip; + + return map {{ + write => 1, + only => [$device->ip], + community => $_, + }} split(m/\s*,\s*/,$1); + } + } + else { + my $stanza = undef; + try { + $stanza = from_json( $line ); + debug sprintf '[%s] external credentials stanza added', + $device->ip; + } + catch { + info sprintf '[%s] error! failed to parse external credentials stanza', + $device->ip; + }; + return $stanza if ref $stanza; + } + } + } + + return (); +} + +true; diff --git a/lib/App/Netdisco/Util/SNMP.pm b/lib/App/Netdisco/Util/SNMP.pm index 3fa6c0a6..ba5b54d6 100644 --- a/lib/App/Netdisco/Util/SNMP.pm +++ b/lib/App/Netdisco/Util/SNMP.pm @@ -1,14 +1,11 @@ package App::Netdisco::Util::SNMP; use Dancer qw/:syntax :script/; -use App::Netdisco::Util::DNS 'hostname_from_ip'; -use App::Netdisco::Util::Permission ':all'; +use App::Netdisco::Util::DeviceAuth 'get_external_credentials'; use base 'Exporter'; our @EXPORT = (); -our @EXPORT_OK = qw/ - fixup_device_auth get_communities snmp_comm_reindex -/; +our @EXPORT_OK = qw/ get_communities snmp_comm_reindex /; our %EXPORT_TAGS = (all => \@EXPORT_OK); =head1 NAME @@ -24,72 +21,6 @@ subroutines. =head1 EXPORT_OK -=head2 fixup_device_auth - -Rebuilds the C config with missing defaults and other fixups for -config changes over time. Returns a list which can replace C. - -=cut - -sub fixup_device_auth { - my $config = (setting('snmp_auth') || setting('device_auth')); - my @new_stanzas = (); - - # new style snmp config - foreach my $stanza (@$config) { - # user tagged - my $tag = ''; - if (1 == scalar keys %$stanza) { - $tag = (keys %$stanza)[0]; - $stanza = $stanza->{$tag}; - - # corner case: untagged lone community - if ($tag eq 'community') { - $tag = $stanza; - $stanza = {community => $tag}; - } - } - - # defaults - $stanza->{tag} ||= $tag; - $stanza->{read} = 1 if !exists $stanza->{read}; - $stanza->{no} ||= []; - $stanza->{only} ||= ['any']; - - die "error: config: snmpv2 community in device_auth must be single item, not list\n" - if ref $stanza->{community}; - - die "error: config: stanza in device_auth must have a tag\n" - if not $stanza->{tag} and exists $stanza->{user}; - - push @new_stanzas, $stanza - } - - # legacy config - # note: read strings tried before write - # note: read-write is no longer used for read operations - - push @new_stanzas, map {{ - read => 1, write => 0, - no => [], only => ['any'], - community => $_, - }} @{setting('community') || []}; - - push @new_stanzas, map {{ - write => 1, read => 0, - no => [], only => ['any'], - community => $_, - }} @{setting('community_rw') || []}; - - foreach my $stanza (@new_stanzas) { - $stanza->{driver} ||= 'snmp' - if exists $stanza->{community} - or exists $stanza->{user}; - } - - return @new_stanzas; -} - =head2 get_communities( $device, $mode ) Takes the current C setting and pushes onto the front of the list @@ -106,8 +37,7 @@ sub get_communities { my @communities = (); # first of all, use external command if configured - push @communities, _get_external_community($device, $mode) - if setting('get_community') and length setting('get_community'); + push @communities, get_external_credentials($device, $mode); # last known-good by tag my $tag_name = 'snmp_auth_tag_'. $mode; @@ -145,46 +75,6 @@ sub get_communities { return ( @communities, @$config ); } -sub _get_external_community { - my ($device, $mode) = @_; - my $cmd = setting('get_community'); - my $ip = $device->ip; - my $host = ($device->dns || hostname_from_ip($ip) || $ip); - - if (defined $cmd and length $cmd) { - # replace variables - $cmd =~ s/\%HOST\%/$host/egi; - $cmd =~ s/\%IP\%/$ip/egi; - - my $result = `$cmd`; # BACKTICKS - return () unless defined $result and length $result; - - my @lines = split (m/\n/, $result); - foreach my $line (@lines) { - if ($line =~ m/^community\s*=\s*(.*)\s*$/i) { - if (length $1 and $mode eq 'read') { - return map {{ - read => 1, - only => [$device->ip], - community => $_, - }} split(m/\s*,\s*/,$1); - } - } - elsif ($line =~ m/^setCommunity\s*=\s*(.*)\s*$/i) { - if (length $1 and $mode eq 'write') { - return map {{ - write => 1, - only => [$device->ip], - community => $_, - }} split(m/\s*,\s*/,$1); - } - } - } - } - - return (); -} - =head2 snmp_comm_reindex( $snmp, $device, $vlan ) Takes an established L instance and makes a fresh connection using diff --git a/share/config.yml b/share/config.yml index 24b31d66..9767019a 100644 --- a/share/config.yml +++ b/share/config.yml @@ -216,7 +216,7 @@ device_identity: [] community: [] community_rw: [] device_auth: [] -get_community: "" +get_credentials: "" bulkwalk_off: false bulkwalk_no: [] bulkwalk_repeaters: 20