diff --git a/Changes b/Changes index 81d682c7..2759c7ce 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ [ENHANCEMENTS] * #408 improvements to MakeRancidConf (earendilfr) + * #410 improvements to Undiscovered Neighbors report 2.039028 - 2018-05-05 diff --git a/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm b/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm index 427e716d..1fe1c1d5 100644 --- a/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm +++ b/lib/App/Netdisco/DB/Result/Virtual/UndiscoveredNeighbors.pm @@ -11,28 +11,32 @@ __PACKAGE__->table_class('DBIx::Class::ResultSource::View'); __PACKAGE__->table('undiscovered_neighbors'); __PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL'); - SELECT DISTINCT ON (p.remote_ip) d.ip, - d.name, - d.dns, - p.port, - p.remote_ip, - p.remote_id, - p.remote_type, - p.remote_port, - a.log, - a.finished - FROM device_port p - JOIN device d - ON d.ip = p.ip - LEFT JOIN admin a - ON (p.remote_ip = a.device AND a.action = 'discover') - WHERE - (p.remote_ip NOT IN (SELECT alias FROM device_ip)) - OR - ((p.remote_ip IS NULL) AND p.is_uplink) - ORDER BY - p.remote_ip ASC, - a.finished DESC + SELECT DISTINCT ON (p.remote_ip, p.port) + 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, + l.log AS comment, + a.log, a.finished + + FROM device_port p + + 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_log l USING (ip, port) + LEFT OUTER JOIN admin a + ON (p.remote_ip = a.device AND a.action = 'discover') + + WHERE + ds.device IS NULL + AND ((p.remote_ip NOT IN (SELECT alias FROM device_ip)) + OR ((p.remote_ip IS NULL) AND p.is_uplink)) + + ORDER BY + p.remote_ip ASC, + p.port ASC, + l.creation DESC, + a.finished DESC ENDSQL __PACKAGE__->add_columns( @@ -44,6 +48,8 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "port", { data_type => "text", is_nullable => 0 }, + "port_description", + { data_type => "text", is_nullable => 0 }, "remote_ip", { data_type => "inet", is_nullable => 1 }, "remote_port", @@ -52,6 +58,8 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "remote_id", { data_type => "text", is_nullable => 1 }, + "comment", + { data_type => "text", is_nullable => 1 }, "log", { data_type => "text", is_nullable => 1 }, "finished", diff --git a/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm b/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm index 7fb81804..d409d3cb 100644 --- a/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/AdminTask/UndiscoveredNeighbors.pm @@ -18,29 +18,28 @@ register_admin_task( get '/ajax/content/admin/undiscoveredneighbors' => require_role admin => sub { my @results - = schema('netdisco')->resultset('Virtual::UndiscoveredNeighbors') - ->order_by('ip')->hri->all; + = schema('netdisco')->resultset('Virtual::UndiscoveredNeighbors')->hri->all; return unless scalar @results; # Don't include devices excluded from discovery by config - # but only if the number of devices is small, as it triggers a - # SELECT per device to check. - if (scalar @results < 50) { - @results - = grep { is_discoverable( $_->{'remote_ip'}, $_->{'remote_type'} ) } - @results; + my @discoverable_results = (); + foreach my $r (@results) { + # 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} ); + push @discoverable_results, $r; } - return unless scalar @results; + return unless scalar @discoverable_results; if ( request->is_ajax ) { template 'ajax/admintask/undiscoveredneighbors.tt', - { results => \@results, }, + { results => \@discoverable_results, }, { layout => undef }; } else { header( 'Content-Type' => 'text/comma-separated-values' ); template 'ajax/admintask/undiscoveredneighbors_csv.tt', - { results => \@results, }, + { results => \@discoverable_results, }, { layout => undef }; } }; diff --git a/share/views/ajax/admintask/undiscoveredneighbors.tt b/share/views/ajax/admintask/undiscoveredneighbors.tt index 5bcfb7af..c8ec1624 100644 --- a/share/views/ajax/admintask/undiscoveredneighbors.tt +++ b/share/views/ajax/admintask/undiscoveredneighbors.tt @@ -1,31 +1,29 @@ - + - - + + [% FOREACH row IN results %] + [% NEXT IF NOT row.remote_ip %] - - - - + + + [% END %]
Observing DeviceObserving Interface Undiscovered NeighborLast Discovery AttemptLast Discovery LogNeighbor IDLast Discovery
- [% row.dns || row.name || row.ip | html_entity %] ( [% row.port | html_entity %] ) - [% IF row.remote_ip %] - - [% row.remote_ip | html_entity %] - ([% row.remote_port | html_entity %]) - [% '
' IF row.remote_id or row.remote_type %] - [% ' id: '_ row.remote_id IF row.remote_id %] - [% ' type: '_ row.remote_type IF row.remote_type %] - [% ELSE %] - Known Device's MAC Address seen on this Port during Macsuck - [% END %] +
+ [% row.dns || row.name || row.ip | html_entity %]
+ + [% row.port | html_entity %] + [% IF row.port_description %]
[% row.port_description | html_entity %][% END %] + [% IF row.comment %]
"[% row.comment | html_entity %]"[% END %]
[% row.finished | html_entity %][% row.log | html_entity %] + [% row.remote_ip | html_entity %]
+ [% row.remote_port | html_entity %]
[% row.remote_id | html_entity %]
+ [% row.remote_type | remove('(?:(?:C|c)opyright\s+)?\(c\).*') | remove('Technical Support: http://.*') | html_entity | html_line_break %]
[% row.finished | html_entity %]
[% row.log | html_entity %]