update undiscovered neighbors and port properties discovery to use remote_is_discoverable

This commit is contained in:
Oliver Gorwits
2022-05-15 23:16:49 +01:00
parent 1a810d89f3
commit e1bfd917a9
4 changed files with 12 additions and 16 deletions

View File

@@ -15,7 +15,7 @@ __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
d.ip, d.name, d.dns, d.ip, d.name, d.dns,
p.port, p.name AS port_description, p.port, p.name AS port_description,
p.remote_ip, p.remote_id, p.remote_type, p.remote_port, p.remote_ip, p.remote_id, p.remote_type, p.remote_port,
dpp.remote_is_wap, dpp.remote_is_phone, dpp.remote_is_discoverable, dpp.remote_is_wap, dpp.remote_is_phone,
l.log AS comment, l.log AS comment,
a.log, a.finished a.log, a.finished
@@ -31,6 +31,7 @@ __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
WHERE WHERE
ds.device IS NULL ds.device IS NULL
AND dpp.remote_is_discoverable
AND ((p.remote_ip NOT IN (SELECT alias FROM device_ip)) AND ((p.remote_ip NOT IN (SELECT alias FROM device_ip))
OR ((p.remote_ip IS NULL) AND p.is_uplink)) OR ((p.remote_ip IS NULL) AND p.is_uplink))
@@ -60,6 +61,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 }, { data_type => "text", is_nullable => 1 },
"remote_id", "remote_id",
{ data_type => "text", is_nullable => 1 }, { data_type => "text", is_nullable => 1 },
"remote_is_discoverable",
{ data_type => "boolean", is_nullable => 1 },
"remote_is_wap", "remote_is_wap",
{ data_type => "boolean", is_nullable => 1 }, { data_type => "boolean", is_nullable => 1 },
"remote_is_phone", "remote_is_phone",

View File

@@ -21,27 +21,15 @@ get '/ajax/content/admin/undiscoveredneighbors' => require_role admin => sub {
= schema('netdisco')->resultset('Virtual::UndiscoveredNeighbors')->hri->all; = schema('netdisco')->resultset('Virtual::UndiscoveredNeighbors')->hri->all;
return unless scalar @results; return unless scalar @results;
# Don't include devices excluded from discovery by config
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} );
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;
if ( request->is_ajax ) { if ( request->is_ajax ) {
template 'ajax/admintask/undiscoveredneighbors.tt', template 'ajax/admintask/undiscoveredneighbors.tt',
{ results => \@discoverable_results, }, { results => \@results, },
{ layout => undef }; { layout => undef };
} }
else { else {
header( 'Content-Type' => 'text/comma-separated-values' ); header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/admintask/undiscoveredneighbors_csv.tt', template 'ajax/admintask/undiscoveredneighbors_csv.tt',
{ results => \@discoverable_results, }, { results => \@results, },
{ layout => undef }; { layout => undef };
} }
}; };

View File

@@ -8,7 +8,7 @@ use App::Netdisco::Transport::SNMP ();
use Dancer::Plugin::DBIC 'schema'; use Dancer::Plugin::DBIC 'schema';
use Encode; use Encode;
use App::Netdisco::Util::Device 'match_to_setting'; use App::Netdisco::Util::Device qw/is_discoverable match_to_setting/;
register_worker({ phase => 'main', driver => 'snmp' }, sub { register_worker({ phase => 'main', driver => 'snmp' }, sub {
my ($job, $workerconf) = @_; my ($job, $workerconf) = @_;
@@ -93,6 +93,9 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
if scalar grep {match_to_setting($_, 'phone_capabilities')} @$remote_cap if scalar grep {match_to_setting($_, 'phone_capabilities')} @$remote_cap
or match_to_setting($remote_type, 'phone_platforms'); or match_to_setting($remote_type, 'phone_platforms');
$properties{ $port }->{remote_is_discoverable} = 'false'
unless is_discoverable($device_ports->{$port}->remote_ip, $remote_type, $remote_cap);
next unless scalar grep {defined && m/^inventory$/} @{ $rem_media_cap->{$idx} }; next unless scalar grep {defined && m/^inventory$/} @{ $rem_media_cap->{$idx} };
$properties{ $port }->{remote_vendor} = $rem_vendor->{ $idx }; $properties{ $port }->{remote_vendor} = $rem_vendor->{ $idx };

View File

@@ -2,4 +2,6 @@ BEGIN;
ALTER TABLE device_port_properties ADD COLUMN "remote_is_discoverable" bool DEFAULT true; ALTER TABLE device_port_properties ADD COLUMN "remote_is_discoverable" bool DEFAULT true;
UPDATE device_port_properties SET remote_is_discoverable = true;
COMMIT; COMMIT;