blib/lib/App/Netdisco/Web/Plugin/Report/ApClients.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 50 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::Netdisco::Web::Plugin::Report::ApClients;
2  
3 use Dancer ':syntax';
4 use Dancer::Plugin::DBIC;
5 use Dancer::Plugin::Auth::Extensible;
6  
7 use App::Netdisco::Web::Plugin;
8  
9 register_report(
10 { category => 'Wireless',
11 tag => 'apclients',
12 label => 'Access Point Client Count',
13 provides_csv => 1,
14 api_endpoint => 1,
15 }
16 );
17  
18 get '/ajax/content/report/apclients' => require_login sub {
19 my @results = schema(vars->{'tenant'})->resultset('Node')->search(
20 { 'wireless_port.port' => { '!=', undef },
21 'me.time_last' => { '>=', \'device.last_macsuck' },
22 },
23 { select => [qw/device.ip device.dns device.name device.model device_port.port device_port.name device_port.type wireless_current.ssid/],
24 as => [qw/ip dns name model port port_name port_type ssid/],
25 join => [qw/device device_port wireless_port wireless_current/],
26 '+columns' => [
27 { 'mac_count' => { count => 'me.mac' } },
28 ],
29 group_by => [
30 'device.ip', 'device.dns', 'device.name', 'device.model',
31 'device_port.port', 'device_port.name', 'device_port.type', 'wireless_current.ssid',
32 ],
33 order_by => { -asc => [qw/device.name device_port.name wireless_current.ssid/] },
34 }
35 )->hri->all;
36  
37 return unless scalar @results;
38  
39 # clients with no SSID seen on the last macsuck are still counted, in
40 # their own row; a blank cell read as a missing row
41 for my $row (@results) {
42 $row->{ssid} = 'Unknown' unless defined $row->{ssid} and length $row->{ssid};
43 }
44  
45 if ( request->is_ajax ) {
46 my $json = to_json( \@results );
47 template 'ajax/report/apclients.tt', { results => $json }, { layout => 'noop' };
48 }
49 else {
50 header( 'Content-Type' => 'text/comma-separated-values' );
51 template 'ajax/report/apclients_csv.tt',
52 { results => \@results }, { layout => 'noop' };
53 }
54 };
55  
56 1;