Add Nodes discovered through LLDP/CDP report

This commit is contained in:
Oliver Gorwits
2014-08-25 16:45:38 +01:00
parent 3b6ae9e58e
commit 4c08de9512
9 changed files with 116 additions and 41 deletions

View File

@@ -3,6 +3,7 @@
[NEW FEATURES]
* netdisco-sshcollector script to get ARP data on devices without SNMP (C. Ramseyer)
* Add Nodes discovered through LLDP/CDP report (replaces IP Phones report)
[ENHANCEMENTS]

View File

@@ -1,4 +1,4 @@
package App::Netdisco::DB::Result::Virtual::PhonesDiscovered;
package App::Netdisco::DB::Result::Virtual::NodesDiscovered;
use strict;
use warnings;
@@ -7,7 +7,7 @@ use base 'DBIx::Class::Core';
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
__PACKAGE__->table('phones_discovered');
__PACKAGE__->table('nodes_discovered');
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
SELECT d.ip,
@@ -35,7 +35,6 @@ WHERE d.ip = p.ip
AND q.port = p.remote_port)
AND p.remote_ip IS NOT NULL
AND p.remote_port IS NOT NULL
AND p.remote_type ILIKE '%ip_phone%'
ENDSQL
);

View File

@@ -0,0 +1,54 @@
package App::Netdisco::Web::Plugin::Report::NodesDiscovered;
use Dancer ':syntax';
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
use App::Netdisco::Util::Web 'sql_match';
register_report(
{ category => 'Node',
tag => 'nodesdiscovered',
label => 'Nodes discovered through LLDP/CDP',
provides_csv => 1,
}
);
get '/ajax/content/report/nodesdiscovered' => require_login sub {
my $op = param('matchall') ? '-and' : '-or';
my @results = schema('netdisco')->resultset('Virtual::NodesDiscovered')
->search({
$op => [
(param('aps') ?
('me.remote_type' => { -ilike => 'AP:%' }) : ()),
(param('phones') ?
('me.remote_type' => { -ilike => '%ip_phone%' }) : ()),
(param('remote_id') ?
('me.remote_id' => { -ilike => scalar sql_match(param('remote_id')) }) : ()),
(param('remote_type') ? ('-or' => [
map {( 'me.remote_type' => { -ilike => scalar sql_match($_) } )}
grep { $_ }
(ref param('remote_type') ? @{param('remote_type')} : param('remote_type'))
]) : ()),
],
})
->hri->all;
return unless scalar @results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/nodesdiscovered.tt', { results => $json },
{ layout => undef };
}
else {
header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/report/nodesdiscovered_csv.tt',
{ results => \@results },
{ layout => undef };
}
};
1;

View File

@@ -1,36 +0,0 @@
package App::Netdisco::Web::Plugin::Report::PhonesDiscovered;
use Dancer ':syntax';
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_report(
{ category => 'Node',
tag => 'phonesdiscovered',
label => 'IP Phones discovered through LLDP/CDP',
provides_csv => 1,
}
);
get '/ajax/content/report/phonesdiscovered' => require_login sub {
my @results = schema('netdisco')->resultset('Virtual::PhonesDiscovered')
->hri->all;
return unless scalar @results;
if ( request->is_ajax ) {
my $json = to_json( \@results );
template 'ajax/report/phonesdiscovered.tt', { results => $json },
{ layout => undef };
}
else {
header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/report/phonesdiscovered_csv.tt',
{ results => \@results },
{ layout => undef };
}
};
1;

View File

@@ -8,7 +8,7 @@ get '/report/*' => require_login sub {
my ($tag) = splat;
# used in the report search sidebar to populate select inputs
my ( $domain_list, $class_list, $ssid_list, $vendor_list );
my ( $domain_list, $class_list, $ssid_list, $type_list, $vendor_list );
if ( $tag eq 'netbios' ) {
$domain_list = [ schema('netdisco')->resultset('NodeNbt')
@@ -31,6 +31,10 @@ get '/report/*' => require_login sub {
$ssid_list = [ schema('netdisco')->resultset('DevicePortSsid')
->get_distinct_col('ssid') ];
}
elsif ( $tag eq 'nodesdiscovered' ) {
$type_list = [ schema('netdisco')->resultset('DevicePort')
->get_distinct_col('remote_type') ];
}
elsif ( $tag eq 'nodevendor' ) {
$vendor_list = [
schema('netdisco')->resultset('Node')->search(
@@ -54,6 +58,7 @@ get '/report/*' => require_login sub {
domain_list => $domain_list,
class_list => $class_list,
ssid_list => $ssid_list,
type_list => $type_list,
vendor_list => $vendor_list,
};
};

View File

@@ -54,7 +54,7 @@ web_plugins:
- Report::Netbios
- Report::NodeMultiIPs
- Report::NodeVendor
- Report::PhonesDiscovered
- Report::NodesDiscovered
- Report::SsidInventory
- Report::VlanInventory
- Report::SubnetUtilization

View File

@@ -0,0 +1,52 @@
<p class="nd_sidebar-title"><em>Node Search Options</em></p>
<input name="q" value="[% params.q | html_entity %]" type="hidden"/>
<div class="clearfix">
<input class="nd_side-input" placeholder="Remote ID (host name)"
type="text" name="remote_id" value="[% params.name | html_entity %]"
rel="tooltip" data-placement="left" data-offset="5" data-title="Remote ID"/>
</div>
<div class="clearfix">
<input class="nd_side-input" placeholder="Remote Type (platform)"
type="text" name="remote_type" value="[% params.name | html_entity %]"
rel="tooltip" data-placement="left" data-offset="5" data-title="Remote Type"/>
</div>
<div class="clearfix">
<select class="nd_side-select nd_colored-input" size="[% type_list.size > 8 ? 8 : type_list.size %]"
multiple="on" name="remote_type"
rel="tooltip" data-placement="left" data-offset="5" data-title="Remote Type"/>
[% FOREACH opt IN type_list %]
<option[% ' selected="selected"' IF type_lkp.exists(opt) %]>[% opt | html_entity %]</option>
[% END %]
</select>
</div>
<div class="clearfix input-prepend">
<label class="add-on">
<input type="checkbox" id="phones"
name="phones"[% ' checked="checked"' IF params.phones %]/>
</label>
<label class="nd_checkboxlabel" for="phones">
<span class="nd_searchcheckbox uneditable-input"><i class="icon-li icon-phone"></i>&nbsp; IP Phones</span>
</label>
</div>
<div class="clearfix input-prepend">
<label class="add-on">
<input type="checkbox" id="aps"
name="aps"[% ' checked="checked"' IF params.aps %]/>
</label>
<label class="nd_checkboxlabel" for="aps">
<span class="nd_searchcheckbox uneditable-input"><i class="icon-li icon-signal"></i>&nbsp Wireless APs</span>
</label>
</div>
<div class="clearfix"><p></p></div>
<div class="clearfix input-prepend">
<label class="add-on">
<input type="checkbox" id="matchall"
name="matchall"[% ' checked="checked"' IF params.matchall %]/>
</label>
<label class="nd_checkboxlabel" for="matchall">
<span class="nd_searchcheckbox uneditable-input">Match All Options</span>
</label>
</div>
<button id="[% tab.tag %]_submit" type="submit" class="btn btn-info">
<i class="icon-search icon-large pull-left nd_navbar-icon"></i> Search Nodes</button>