Link from the subnet utilization report to ip inventory report for each subnet with the same date range.
This commit is contained in:
		| @@ -1,9 +1,11 @@ | ||||
| package App::Netdisco::Util::Web; | ||||
|  | ||||
| use base 'Exporter'; | ||||
| use Time::Piece; | ||||
| use Time::Seconds; | ||||
| our @EXPORT = (); | ||||
| our @EXPORT_OK = qw/ | ||||
|   sort_port | ||||
|   sort_port sort_modules interval_to_daterange | ||||
| /; | ||||
| our %EXPORT_TAGS = (all => \@EXPORT_OK); | ||||
|  | ||||
| @@ -150,4 +152,34 @@ sub sort_modules { | ||||
|     return \%modules; | ||||
| } | ||||
|  | ||||
| =head2 interval_to_daterange( $interval ) | ||||
|  | ||||
| Takes an interval in days, weeks, months, or years in a format like '7 days' | ||||
| and returns a date range in the format 'YYYY-MM-DD to YYYY-MM-DD' by | ||||
| subtracting the interval from the current date. | ||||
|  | ||||
| =cut | ||||
|  | ||||
| sub interval_to_daterange { | ||||
|     my $interval = shift; | ||||
|  | ||||
|     return unless $interval =~ m/^(?:\d+)\s+(?:day|week|month|year)s?$/; | ||||
|  | ||||
|     my %const = ( | ||||
|         day   => ONE_DAY, | ||||
|         week  => ONE_WEEK, | ||||
|         month => ONE_MONTH, | ||||
|         year  => ONE_YEAR | ||||
|     ); | ||||
|  | ||||
|     my ( $amt, $factor ) | ||||
|         = $interval =~ /^(\d+)\s+(day|week|month|year)s?$/gmx; | ||||
|  | ||||
|     $amt-- if $factor eq 'day'; | ||||
|  | ||||
|     my $start = Time::Piece->new - $const{$factor} * $amt; | ||||
|  | ||||
|     return $start->ymd . " to " . Time::Piece->new->ymd; | ||||
| } | ||||
|  | ||||
| 1; | ||||
|   | ||||
| @@ -5,6 +5,7 @@ use Dancer::Plugin::DBIC; | ||||
| use Dancer::Plugin::Auth::Extensible; | ||||
|  | ||||
| use App::Netdisco::Web::Plugin; | ||||
| use App::Netdisco::Util::Web (); # for interval_to_daterange | ||||
|  | ||||
| register_report({ | ||||
|   category     => 'IP', | ||||
| @@ -18,13 +19,16 @@ get '/ajax/content/report/subnets' => require_login sub { | ||||
|     my $age = param('age') || '7 days'; | ||||
|     $age = '7 days' unless $age =~ m/^(?:\d+)\s+(?:day|week|month|year)s?$/; | ||||
|  | ||||
|     my $daterange = App::Netdisco::Util::Web::interval_to_daterange($age); | ||||
|  | ||||
|     my $set = schema('netdisco')->resultset('Virtual::SubnetUtilization') | ||||
|       ->search(undef,{ | ||||
|         bind => [ $subnet, $age, $age, $subnet, $age, $age ], | ||||
|       }); | ||||
|  | ||||
|     if ( request->is_ajax ) { | ||||
|         template 'ajax/report/subnets.tt', { results => $set, }, | ||||
|         template 'ajax/report/subnets.tt', | ||||
|             { results => $set, daterange => $daterange }, | ||||
|             { layout => undef }; | ||||
|     } | ||||
|     else { | ||||
|   | ||||
| @@ -13,7 +13,8 @@ | ||||
|   </tbody> | ||||
|     [% FOREACH row IN results.all %] | ||||
|     <tr> | ||||
|       <td class="nd_center-cell">[% row.subnet | html_entity %]</td> | ||||
|       <td class="nd_center-cell"><a href="[% uri_for('/report/ipinventory') %]?subnet=[% row.subnet | uri %]&daterange=[% daterange | uri %]&limit=[% row.subnet_size | uri %]&age_on=on"> | ||||
|                [% row.subnet | html_entity %]</a></td> | ||||
|       <td class="nd_center-cell">[% row.subnet_size | html_entity %]</td> | ||||
|       <td class="nd_center-cell">[% row.active | html_entity %]</td> | ||||
|       <td class="nd_center-cell">[% row.percent | html_entity %]</td> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user