Add IP Phones discovered through LLDP/CDP report

This commit is contained in:
Eric A. Miller
2013-12-16 23:14:41 -05:00
parent 5d3216552f
commit d963ad3148
6 changed files with 146 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
2.030000 - 2.030000 -
[NEW FEATURES]
* Add IP Phones discovered through LLDP/CDP report
[ENHANCEMENTS] [ENHANCEMENTS]
* Require SNMP::Info 3.10+, use new c_cap method to tag device remote_type * Require SNMP::Info 3.10+, use new c_cap method to tag device remote_type

View File

@@ -0,0 +1,69 @@
package App::Netdisco::DB::Result::Virtual::PhonesDiscovered;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
__PACKAGE__->table('phones_discovered');
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
SELECT d.ip,
d.dns,
d.name,
p.port,
p.remote_ip,
p.remote_port,
p.remote_type,
p.remote_id
FROM device_port p,
device d
WHERE d.ip = p.ip
AND NOT EXISTS
(SELECT 1
FROM device_port q
WHERE q.ip = p.remote_ip
AND q.port = p.remote_port)
AND NOT EXISTS
(SELECT 1
FROM device_ip a,
device_port q
WHERE a.alias = p.remote_ip
AND q.ip = a.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
);
__PACKAGE__->add_columns(
'ip' => {
data_type => 'inet',
},
'dns' => {
data_type => 'text',
},
'name' => {
data_type => 'text',
},
'port' => {
data_type => 'text',
},
'remote_ip' => {
data_type => 'inet',
},
'remote_port' => {
data_type => 'text',
},
'remote_type' => {
data_type => 'text',
},
'remote_id' => {
data_type => 'text',
},
);
1;

View File

@@ -0,0 +1,32 @@
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 $set = schema('netdisco')->resultset('Virtual::PhonesDiscovered');
return unless $set->count;
if (request->is_ajax) {
template 'ajax/report/phonesdiscovered.tt', { results => $set, },
{ layout => undef };
}
else {
header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/report/phonesdiscovered_csv.tt', { results => $set, },
{ layout => undef };
}
};
true;

View File

@@ -46,6 +46,7 @@ web_plugins:
- Report::DevicePoeStatus - Report::DevicePoeStatus
- Report::DuplexMismatch - Report::DuplexMismatch
- Report::NodeMultiIPs - Report::NodeMultiIPs
- Report::PhonesDiscovered
- Report::SsidInventory - Report::SsidInventory
- Report::VlanInventory - Report::VlanInventory
- AdminTask::JobQueue - AdminTask::JobQueue

View File

@@ -0,0 +1,28 @@
<table class="table table-bordered table-condensed table-striped nd_floatinghead">
<thead>
<tr>
<th class="nd_center-cell">Device</th>
<th class="nd_center-cell">Port</th>
<th class="nd_center-cell">Remote ID</th>
<th class="nd_center-cell">Remote IP</th>
<th class="nd_center-cell">Remote Port</th>
<th class="nd_center-cell">Remote Type</th>
</tr>
</thead>
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td class="nd_center-cell">[% row.dns || row.name || row.ip | html_entity %]</td>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% device_ports %]&q=[% row.dns || row.ip | uri %]&f=[% row.port | uri %]">
[% row.port | html_entity %]</a></td>
<td class="nd_center-cell">[% row.remote_id | html_entity %]</td>
<td class="nd_center-cell"><a class="nd_linkcell"
href="[% search_node %]&q=[% row.remote_ip | uri %]">[% row.remote_ip | html_entity %]</a></td>
<td class="nd_center-cell">[% row.remote_port | html_entity %]</td>
<td class="nd_center-cell">[% row.remote_type | html_entity %]</td>
</tr>
[% END %]
</tbody>
</table>

View File

@@ -0,0 +1,12 @@
[% USE CSV -%]
[% CSV.dump([ 'Device' 'Port' 'Remote ID' 'Remote IP' 'Remote Port' 'Remote Type']) %]
[% WHILE (row = results.next) %]
[% mylist = [] %]
[% device = row.dns || row.name || row.ip %]
[% FOREACH col IN [ device row.port row.remote_id row.remote_ip row.remote_port row.remote_type ] %]
[% mylist.push(col) %]
[% END %]
[% CSV.dump(mylist) %]
[% END %]