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

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 56 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::SubnetUtilization;
2  
3 use Dancer ':syntax';
4 use Dancer::Plugin::DBIC;
5 use Dancer::Plugin::Auth::Extensible;
6  
7 use App::Netdisco::Web::Plugin;
8 use App::Netdisco::Util::L3Domain 'results_span_domains';
9 use POSIX qw/strftime/;
10  
11 register_report({
12 category => 'IP',
13 tag => 'subnets',
14 label => 'Subnet Utilization',
15 provides_csv => 1,
16 api_endpoint => 1,
17 api_parameters => [
18 subnet => {
19 description => 'IP Prefix to search',
20 default => '0.0.0.0/32',
21 },
22 daterange => {
23 description => 'Date range to search',
24 default => ('1970-01-01 to '. strftime('%Y-%m-%d', gmtime)),
25 },
26 age_invert => {
27 description => 'Results should NOT be within daterange',
28 type => 'boolean',
29 default => 'false',
30 },
31 ],
32 });
33  
34 get '/ajax/content/report/subnets' => require_login sub {
35 my $subnet = param('subnet') || '0.0.0.0/32';
36 my $agenot = param('age_invert') || '0';
37  
38 my $daterange = param('daterange')
39 || ('1970-01-01 to '. strftime('%Y-%m-%d', gmtime));
40 my ( $start, $end ) = $daterange =~ /(\d+-\d+-\d+)/gmx;
41 $start = $start . ' 00:00:00';
42 $end = $end . ' 23:59:59';
43  
44 my @results = schema(vars->{'tenant'})->resultset('Virtual::SubnetUtilization')
45 ->search(undef,{
46 bind => [ $subnet, $start, $end, $start, $subnet, $start, $start ],
47 })->hri->all;
48  
49 return unless scalar @results;
50 my $multi_domain = results_span_domains(\@results);
51  
52 if ( request->is_ajax ) {
53 template 'ajax/report/subnets.tt',
54 { results => \@results, multi_domain => $multi_domain }, { layout => 'noop' };
55 }
56 else {
57 header( 'Content-Type' => 'text/comma-separated-values' );
58 template 'ajax/report/subnets_csv.tt',
59 { results => \@results, multi_domain => $multi_domain }, { layout => 'noop' };
60 }
61 };
62  
63 1;