From dc7ea976d7c756d99b172bb9c64850945d778e32 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 10 Sep 2013 22:27:16 +0100 Subject: [PATCH] Wireless AP Reports (jeneric) Squashed commit of the following: commit 567df500f45bca6ead1a1f8b7698253450ad1cb5 Author: Oliver Gorwits Date: Tue Sep 10 22:26:48 2013 +0100 collapse list if more than 10 APs commit 9dddb2432c1a44d19f4cacc75d64e91feb71e665 Author: Eric A. Miller Date: Mon Sep 9 22:35:28 2013 -0400 add port descr commit eca417c46ab7dd07a66054ec0104e62b5099748b Author: Oliver Gorwits Date: Mon Sep 9 21:55:49 2013 +0100 use real port description, and link to filtered ports view commit e4a43e78ffefa3cd3ad528ac7414dcd959beceaa Author: Eric A. Miller Date: Sun Sep 8 23:43:42 2013 -0400 add access point channel distribution report commit b6c803446d2bd02712910535c10a8ea3950ecd62 Author: Eric A. Miller Date: Sun Sep 8 22:06:37 2013 -0400 sync module and file name commit c70d251a17a791fd34a3d58ce5373c97c7d7eba1 Author: Eric A. Miller Date: Sun Sep 8 21:51:45 2013 -0400 perl tidy commit be8bc48d1ea9751164e167f155312f80ca0cf2d9 Author: Eric A. Miller Date: Sun Sep 8 21:49:55 2013 -0400 report ap radio power in both mW and dBm commit 54a88054ab15ee8d0e884e919e040f9f8092824b Author: Eric A. Miller Date: Sun Sep 8 15:47:18 2013 -0400 access point radios channel and power report --- .../DB/Result/Virtual/ApRadioChannelPower.pm | 54 ++++++++++++++++ .../Web/Plugin/Report/ApChannelDist.pm | 34 ++++++++++ .../Web/Plugin/Report/ApRadioChannelPower.pm | 62 +++++++++++++++++++ Netdisco/share/config.yml | 2 + .../share/views/ajax/report/apchanneldist.tt | 17 +++++ .../views/ajax/report/apradiochannelpower.tt | 52 ++++++++++++++++ 6 files changed, 221 insertions(+) create mode 100644 Netdisco/lib/App/Netdisco/DB/Result/Virtual/ApRadioChannelPower.pm create mode 100644 Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm create mode 100644 Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApRadioChannelPower.pm create mode 100644 Netdisco/share/views/ajax/report/apchanneldist.tt create mode 100644 Netdisco/share/views/ajax/report/apradiochannelpower.tt diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/ApRadioChannelPower.pm b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/ApRadioChannelPower.pm new file mode 100644 index 00000000..30707c1b --- /dev/null +++ b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/ApRadioChannelPower.pm @@ -0,0 +1,54 @@ +package App::Netdisco::DB::Result::Virtual::ApRadioChannelPower; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); + +__PACKAGE__->table('ap_radio_channel_power'); +__PACKAGE__->result_source_instance->is_virtual(1); +__PACKAGE__->result_source_instance->view_definition(<add_columns( + 'device_name' => { + data_type => 'text', + }, + 'ip' => { + data_type => 'inet', + }, + 'dns' => { + data_type => 'text', + }, + 'model' => { + data_type => 'text', + }, + 'location' => { + data_type => 'text', + }, + 'port' => { + data_type => 'text', + }, + 'port_name' => { + data_type => 'text', + }, + 'descr' => { + data_type => 'text', + }, + 'channel' => { + data_type => 'integer', + }, + 'power' => { + data_type => 'integer', + }, +); + +1; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm new file mode 100644 index 00000000..98e5d21b --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApChannelDist.pm @@ -0,0 +1,34 @@ +package App::Netdisco::Web::Plugin::Report::ApChannelDist; + +use Dancer ':syntax'; +use Dancer::Plugin::Ajax; +use Dancer::Plugin::DBIC; +use Dancer::Plugin::Auth::Extensible; + +use App::Netdisco::Web::Plugin; + +register_report( + { category => 'Wireless', + tag => 'apchanneldist', + label => 'Access Point Channel Distribution', + } +); + +ajax '/ajax/content/report/apchanneldist' => require_login sub { + my $set = schema('netdisco')->resultset('DevicePortWireless')->search( + { channel => { '!=', '0' } }, + { select => [ 'channel', { count => 'channel' } ], + as => [qw/ channel ch_count /], + group_by => [qw/channel/], + order_by => { -desc => [qw/count/] }, + }, + ); + + return unless $set->count; + + content_type('text/html'); + template 'ajax/report/apchanneldist.tt', { results => $set, }, + { layout => undef }; +}; + +true; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApRadioChannelPower.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApRadioChannelPower.pm new file mode 100644 index 00000000..e294d718 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApRadioChannelPower.pm @@ -0,0 +1,62 @@ +package App::Netdisco::Web::Plugin::Report::ApRadioChannelPower; + +use Dancer ':syntax'; +use Dancer::Plugin::Ajax; +use Dancer::Plugin::DBIC; +use Dancer::Plugin::Auth::Extensible; + +use App::Netdisco::Web::Plugin; + +register_report( + { category => 'Wireless', + tag => 'apradiochannelpower', + label => 'Access Point Radios Channel and Power', + } +); + +sub port_tree { + my $devices = shift; + + my %ports; + + foreach my $device (@$devices) { + my $power2; + + if ( defined( $device->power ) && $device->power ) { + $power2 = sprintf( "%.1f", + 10.0 * CORE::log( $device->power ) / CORE::log(10) ); + } + + $ports{ $device->device_name }{device} = { + name => $device->device_name, + ip => $device->ip, + dns => $device->dns, + model => $device->model, + location => $device->location + }; + push @{ $ports{ $device->device_name }{ports} }, + { + port => $device->port, + name => $device->port_name, + descr => $device->descr, + channel => $device->channel, + power => $device->power, + power2 => $power2 + }; + } + return \%ports; +} + +ajax '/ajax/content/report/apradiochannelpower' => require_login sub { + my @set + = schema('netdisco')->resultset('Virtual::ApRadioChannelPower')->all; + + my $results = port_tree( \@set ); + return unless scalar %$results; + + content_type('text/html'); + template 'ajax/report/apradiochannelpower.tt', { results => $results, }, + { layout => undef }; +}; + +true; diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index ccf7d041..3b6058be 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -34,6 +34,8 @@ path: '/' web_plugins: - Inventory - Report::PortUtilization + - Report::ApChannelDist + - Report::ApRadioChannelPower - Report::HalfDuplex - Report::DuplexMismatch - AdminTask::PseudoDevice diff --git a/Netdisco/share/views/ajax/report/apchanneldist.tt b/Netdisco/share/views/ajax/report/apchanneldist.tt new file mode 100644 index 00000000..2575d998 --- /dev/null +++ b/Netdisco/share/views/ajax/report/apchanneldist.tt @@ -0,0 +1,17 @@ + + + + + + + + + [% WHILE (row = results.next) %] + + + + + [% END %] + +
ChannelCount
[% row.channel %][% row.get_column('ch_count') %]
+ diff --git a/Netdisco/share/views/ajax/report/apradiochannelpower.tt b/Netdisco/share/views/ajax/report/apradiochannelpower.tt new file mode 100644 index 00000000..8d282b2b --- /dev/null +++ b/Netdisco/share/views/ajax/report/apradiochannelpower.tt @@ -0,0 +1,52 @@ +
+[% count = 0 %] +[% FOREACH row IN results.keys.sort %] + [% count = count + 1 %] +
+ +
+
+ + + + + + + + + + + + [% FOREACH p IN results.$row.ports %] + [% NEXT UNLESS p.channel # No channel port is admin down %] + + + + + + + + [% END %] + +
PortNameDescriptionChannelTx Power (mW/dBm)
+ + [% p.port | html_entity %][% p.name %][% p.descr %][% p.channel %][% IF p.power or p.power2 %][% p.power %] / [% p.power2 %][% END %]
+
+
+[%END%] +
+ +