1package App::Netdisco::Web::Plugin::Report::PortUtilization; 2 3use Dancer ':syntax'; 4use Dancer::Plugin::DBIC; 5use Dancer::Plugin::Auth::Extensible; 6 7use App::Netdisco::Web::Plugin; 8 9register_report( 10 { category => 'Device', 11 tag => 'portutilization', 12 label => 'Port Utilization', 13 provides_csv => 1, 14 api_endpoint => 1, 15 api_parameters => [ 16 age_num => { 17 description => 'Mark as Free if down for (quantity)', 18 enum => [1 .. 31], 19 default => '3', 20 }, 21 age_unit => { 22 description => 'Mark as Free if down for (period)', 23 enum => [qw/days weeks months years/], 24 default => 'months', 25 }, 26 ], 27 } 28); 29 30get '/ajax/content/report/portutilization' => require_login sub { 31 return unless schema('netdisco')->resultset('Device')->count; 32 33 my $age_num = param('age_num') || 3; 34 my $age_unit = param('age_unit') || 'months'; 35 my @results = schema('netdisco')->resultset('Virtual::PortUtilization') 36 ->search(undef, { bind => [ "$age_num $age_unit", "$age_num $age_unit", "$age_num $age_unit" ] })->hri->all; 37 38 if (request->is_ajax) { 39 my $json = to_json (\@results); 40 template 'ajax/report/portutilization.tt', { results => $json }; 41 } 42 else { 43 header( 'Content-Type' => 'text/comma-separated-values' ); 44 template 'ajax/report/portutilization_csv.tt', { results => \@results, }; 45 } 46}; 47 481; 49