fix IP Inventory report to work without daterange

This commit is contained in:
Oliver Gorwits
2014-02-22 10:39:13 +00:00
parent 09a63e4183
commit 6eb88bc443
4 changed files with 24 additions and 29 deletions

View File

@@ -10,6 +10,7 @@ use Socket6 (); # to ensure dependency is met
use HTML::Entities (); # to ensure dependency is met
use URI::QueryParam (); # part of URI, to add helper methods
use Path::Class 'dir';
use App::Netdisco::Util::Web 'interval_to_daterange';
use App::Netdisco::Web::AuthN;
use App::Netdisco::Web::Static;
@@ -62,6 +63,9 @@ hook 'before_template' => sub {
# access to logged in user's roles
$tokens->{user_has_role} = sub { user_has_role(@_) };
# create date ranges from within templates
$tokens->{to_daterange} = sub { interval_to_daterange(@_) };
# fix Plugin Template Variables to be only path+query
$tokens->{$_} = $tokens->{$_}->path_query
for qw/search_node search_device device_ports/;

View File

@@ -15,24 +15,6 @@ register_report(
}
);
# Following two Perl Core 5.10+
use Time::Piece;
use Time::Seconds;
hook 'before' => sub {
return
unless ( request->path eq uri_for('/report/ipinventory')->path
or index( request->path, uri_for('/ajax/content/report/ipinventory')->path )
== 0 );
my $start = Time::Piece->new - ONE_DAY * 29;
params->{'limit'} ||= 256;
params->{'daterange'}
||= $start->ymd . " to " . Time::Piece->new->ymd;
};
get '/ajax/content/report/ipinventory' => require_login sub {
# Default to something simple with no results to prevent
@@ -53,7 +35,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
# 'never' is true. TODO: Need better input validation, both JS and
# server-side to provide user feedback
$limit = 8192 if $limit > 8192;
$order = $order eq 'IP' ? \'ip ASC' : \'age DESC';
$order = $order eq 'IP' ? {-asc => 'ip'} : [{-desc => 'age'}, {-asc => 'ip'}];
my $rs1 = schema('netdisco')->resultset('DeviceIp')->search(
undef,
@@ -114,8 +96,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
my $rs_sub = $rs_union->search(
{ ip => { '<<' => $subnet->cidr } },
{ order_by => [qw( ip time_last )],
select => [
{ select => [
\'DISTINCT ON (ip) ip',
'dns',
\qq/date_trunc('second', time_last) AS time_last/,
@@ -148,10 +129,16 @@ get '/ajax/content/report/ipinventory' => require_login sub {
}
else {
$rs = $rs_union->search(
{ -and => [
time_last => { '>=', $start },
time_last => { '<=', $end },
]
{ -or => [
-and => [
time_first => undef,
time_last => undef,
],
-and => [
time_last => { '>=', $start },
time_last => { '<=', $end },
],
],
},
{ from => { me => $rs_sub }, }
);