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

filter: Statementstmt 0.0% 0 / 37 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 / 58 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'})->without_jit(sub {
45 schema(vars->{'tenant'})->resultset('Virtual::SubnetUtilization')
46 ->search(undef,{
47 bind => [ $subnet, $start, $end, $start, $subnet, $start, $start ],
48 })->hri->all;
49 });
50  
51 return unless scalar @results;
52 my $multi_domain = results_span_domains(\@results);
53  
54 if ( request->is_ajax ) {
55 template 'ajax/report/subnets.tt',
56 { results => \@results, multi_domain => $multi_domain }, { layout => 'noop' };
57 }
58 else {
59 header( 'Content-Type' => 'text/comma-separated-values' );
60 template 'ajax/report/subnets_csv.tt',
61 { results => \@results, multi_domain => $multi_domain }, { layout => 'noop' };
62 }
63 };
64  
65 1;