From 85ab6e15ecd59c0ccb39d0e620ff1eabf7f43980 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 25 Jan 2015 12:28:35 +0000 Subject: [PATCH] [#181] AP Client Count report was broken The DB query was joining on the device_port_wireless table which as any fule kno isn't using the device port subinterface name so there would always be zero results (as wireless data is related to the subinterface). Fixed the query to use the device_port_ssid table, and also added a dedicated template so additional data can be displayed in the report. --- Netdisco/Changes | 1 + Netdisco/MANIFEST | 2 + .../lib/App/Netdisco/DB/Result/DevicePort.pm | 14 +++++ .../App/Netdisco/DB/Result/DevicePortSsid.pm | 16 +++++ .../Netdisco/Web/Plugin/Report/ApClients.pm | 9 +-- Netdisco/share/views/ajax/report/apclients.tt | 63 +++++++++++++++++++ .../share/views/ajax/report/apclients_csv.tt | 14 +++++ 7 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 Netdisco/share/views/ajax/report/apclients.tt create mode 100644 Netdisco/share/views/ajax/report/apclients_csv.tt diff --git a/Netdisco/Changes b/Netdisco/Changes index a2eb38cc..c7ce0d9c 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -15,6 +15,7 @@ * [#191] Fix error when stopping stopped web daemon * [#174] LDAP users should not be able to change password * [#182] SSID and PoE showing in wrong Device Port columns + * [#181] AP Client Count report was broken 2.030000 - 2015-01-08 diff --git a/Netdisco/MANIFEST b/Netdisco/MANIFEST index e64b6c38..74d2f25d 100644 --- a/Netdisco/MANIFEST +++ b/Netdisco/MANIFEST @@ -326,6 +326,8 @@ share/views/ajax/device/ports.tt share/views/ajax/device/ports_csv.tt share/views/ajax/report/apchanneldist.tt share/views/ajax/report/apchanneldist_csv.tt +share/views/ajax/report/apclients.tt +share/views/ajax/report/apclients_csv.tt share/views/ajax/report/apradiochannelpower.tt share/views/ajax/report/apradiochannelpower_csv.tt share/views/ajax/report/deviceaddrnodns.tt diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm index 8093e42e..137225ed 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/DevicePort.pm @@ -195,6 +195,20 @@ __PACKAGE__->might_have( } ); +=head2 ssid + +Returns a row from the C table if one refers to this +device port. + +=cut + +__PACKAGE__->might_have( + ssid => 'App::Netdisco::DB::Result::DevicePortSsid', + { 'foreign.ip' => 'self.ip', + 'foreign.port' => 'self.port', + } +); + =head2 wireless Returns a row from the C table if one refers to this diff --git a/Netdisco/lib/App/Netdisco/DB/Result/DevicePortSsid.pm b/Netdisco/lib/App/Netdisco/DB/Result/DevicePortSsid.pm index ce54c924..63e23856 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/DevicePortSsid.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/DevicePortSsid.pm @@ -47,5 +47,21 @@ __PACKAGE__->belongs_to( port => 'App::Netdisco::DB::Result::DevicePort', { 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port', }); +=head2 nodes + +Returns the set of Nodes whose MAC addresses are associated with this Device +Port SSID. + +=cut + +__PACKAGE__->has_many( nodes => 'App::Netdisco::DB::Result::Node', + { + 'foreign.switch' => 'self.ip', + 'foreign.port' => 'self.port', + }, + { join_type => 'LEFT', + cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }, +); + # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApClients.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApClients.pm index a11113f7..6bd929e7 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApClients.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/ApClients.pm @@ -18,15 +18,16 @@ get '/ajax/content/report/apclients' => require_login sub { my @results = schema('netdisco')->resultset('Device')->search( { 'nodes.time_last' => { '>=', \'me.last_macsuck' } }, { select => [ 'ip', 'dns', 'name', 'model', 'location' ], - join => { 'ports' => { 'wireless' => 'nodes' } }, + join => { 'ports' => { 'ssid' => 'nodes' } }, '+columns' => [ { 'port' => 'ports.port' }, { 'description' => 'ports.name' }, + { 'ssid' => 'ssid.ssid' }, { 'mac_count' => { count => 'nodes.mac' } }, ], group_by => [ 'me.ip', 'me.dns', 'me.name', 'me.model', - 'me.location', 'ports.port', 'ports.descr', 'ports.name' + 'me.location', 'ports.port', 'ports.descr', 'ports.name', 'ssid.ssid', ], order_by => { -desc => [qw/count/] }, } @@ -36,12 +37,12 @@ get '/ajax/content/report/apclients' => require_login sub { if ( request->is_ajax ) { my $json = to_json( \@results ); - template 'ajax/report/portmultinodes.tt', { results => $json }, + template 'ajax/report/apclients.tt', { results => $json }, { layout => undef }; } else { header( 'Content-Type' => 'text/comma-separated-values' ); - template 'ajax/report/portmultinodes_csv.tt', + template 'ajax/report/apclients_csv.tt', { results => \@results }, { layout => undef }; } diff --git a/Netdisco/share/views/ajax/report/apclients.tt b/Netdisco/share/views/ajax/report/apclients.tt new file mode 100644 index 00000000..ca64c4f8 --- /dev/null +++ b/Netdisco/share/views/ajax/report/apclients.tt @@ -0,0 +1,63 @@ + + + + + + + + + + + +
DeviceModelLocationPortSSIDNode Count
+ + diff --git a/Netdisco/share/views/ajax/report/apclients_csv.tt b/Netdisco/share/views/ajax/report/apclients_csv.tt new file mode 100644 index 00000000..145fc44f --- /dev/null +++ b/Netdisco/share/views/ajax/report/apclients_csv.tt @@ -0,0 +1,14 @@ +[% USE CSV -%] +[% CSV.dump([ 'Device' 'Model' 'Location' 'Port' 'SSID' 'Node Count' ]) %] + +[% FOREACH row IN results %] + [% mylist = [] %] + [% mylist.push(row.dns || row.name || row.ip) %] + [% mylist.push(row.model) %] + [% mylist.push(row.location) %] + [% mylist.push(row.port) %] + [% mylist.push(row.ssid) %] + [% mylist.push(row.mac_count) %] + [% CSV.dump(mylist) %] + +[% END %]