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

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 63 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::VlanInventory;
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 => 'VLAN',
11 tag => 'vlaninventory',
12 label => 'VLAN Inventory',
13 provides_csv => 1,
14 api_endpoint => 1,
15 }
16 );
17  
18 get '/ajax/content/report/vlaninventory' => require_login sub {
19 my @results = schema(vars->{'tenant'})->resultset('DeviceVlan')->search(
20 { 'me.description' => { '!=', 'NULL' },
21 'me.vlan' => { '>' => 0 },
22 'ports.vlan' => { '>' => 0 },
23 },
24 { join => { 'ports' => 'vlan_entry' },
25 select => [
26 'me.vlan',
27 'me.description',
28 { count => { distinct => 'me.ip' } },
29 { count => 'ports.vlan' }
30 ],
31 as => [qw/ vlan description dcount pcount /],
32 group_by => [qw/ me.vlan me.description /],
33 }
34 )->hri->all;
35  
36 return unless scalar @results;
37  
38 if ( request->is_ajax ) {
39 my $json = to_json (\@results);
40 template 'ajax/report/vlaninventory.tt', { results => $json }, { layout => 'noop' };
41 }
42 else {
43 header( 'Content-Type' => 'text/comma-separated-values' );
44 template 'ajax/report/vlaninventory_csv.tt', { results => \@results }, { layout => 'noop' };
45 }
46 };
47  
48 register_report(
49 { category => 'VLAN',
50 tag => 'vlanmultiplenames',
51 label => 'VLANs With Multiple Names',
52 provides_csv => 1,
53 api_endpoint => 1,
54 }
55 );
56  
57 get '/ajax/content/report/vlanmultiplenames' => require_login sub {
58 my @results = schema(vars->{'tenant'})->resultset('DeviceVlan')->search(
59 { 'me.description' => { '!=', 'NULL' },
60 'me.vlan' => { '>' => 0 },
61 'ports.vlan' => { '>' => 0 },
62 },
63 { join => { 'ports' => 'vlan_entry' },
64 select => [
65 'me.vlan',
66 { count => { distinct => 'me.ip' } },
67 { count => 'ports.vlan' },
68 \q{ array_agg(DISTINCT me.description ORDER BY me.description) },
69 ],
70 as => [qw/ vlan dcount pcount description /],
71 group_by => [qw/ me.vlan /],
72 having => \q{ count (DISTINCT me.description) > 1 },
73 }
74 )->hri->all;
75  
76 return unless scalar @results;
77  
78 if ( request->is_ajax ) {
79 my $json = to_json (\@results);
80 template 'ajax/report/vlanmultiplenames.tt', { results => $json }, { layout => 'noop' };
81 }
82 else {
83 header( 'Content-Type' => 'text/comma-separated-values' );
84 template 'ajax/report/vlanmultiplenames_csv.tt', { results => \@results }, { layout => 'noop' };
85 }
86 };
87  
88 true;