« blib/lib/App/Netdisco/Web/Plugin/Report/PortSsid.pm
↑ Summary
blib/lib/App/Netdisco/Web/Plugin/Report/PortVLANMismatch.pm »
| 1 | package App::Netdisco::Web::Plugin::Report::PortUtilization; | ||
| 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 => '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 | |||
| 30 | get '/ajax/content/report/portutilization' => require_login sub { | ||
| 31 | return unless schema(vars->{'tenant'})->resultset('Device')->count; | ||
| 32 | |||
| 33 | my $age_num = param('age_num') || 3; | ||
| 34 | my $age_unit = param('age_unit') || 'months'; | ||
| 35 | my @results = schema(vars->{'tenant'})->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 }, { layout => 'noop' }; | ||
| 41 | } | ||
| 42 | else { | ||
| 43 | header( 'Content-Type' => 'text/comma-separated-values' ); | ||
| 44 | template 'ajax/report/portutilization_csv.tt', { results => \@results, }, { layout => 'noop' }; | ||
| 45 | } | ||
| 46 | }; | ||
| 47 | |||
| 48 | 1; |