fix IP Inventory report to work without daterange
This commit is contained in:
@@ -16,8 +16,10 @@
|
|||||||
|
|
||||||
[BUG FIXES]
|
[BUG FIXES]
|
||||||
|
|
||||||
* Workaround for https://rt.cpan.org/Ticket/Display.html?id=93244 (ECR)
|
* Workaround for https://rt.cpan.org/Ticket/Display.html?id=93244
|
||||||
* Fix for crash when selecting Last Change column in device ports view (ECR)
|
* Fix for crash when selecting Last Change column in device ports view
|
||||||
|
* Fix IP Inventory Report to work without daterange
|
||||||
|
* Fix "list IPs never seen" to work without daterange in IP Inventory Report
|
||||||
|
|
||||||
2.023002 - 2014-02-17
|
2.023002 - 2014-02-17
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use Socket6 (); # to ensure dependency is met
|
|||||||
use HTML::Entities (); # to ensure dependency is met
|
use HTML::Entities (); # to ensure dependency is met
|
||||||
use URI::QueryParam (); # part of URI, to add helper methods
|
use URI::QueryParam (); # part of URI, to add helper methods
|
||||||
use Path::Class 'dir';
|
use Path::Class 'dir';
|
||||||
|
use App::Netdisco::Util::Web 'interval_to_daterange';
|
||||||
|
|
||||||
use App::Netdisco::Web::AuthN;
|
use App::Netdisco::Web::AuthN;
|
||||||
use App::Netdisco::Web::Static;
|
use App::Netdisco::Web::Static;
|
||||||
@@ -62,6 +63,9 @@ hook 'before_template' => sub {
|
|||||||
# access to logged in user's roles
|
# access to logged in user's roles
|
||||||
$tokens->{user_has_role} = sub { user_has_role(@_) };
|
$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
|
# fix Plugin Template Variables to be only path+query
|
||||||
$tokens->{$_} = $tokens->{$_}->path_query
|
$tokens->{$_} = $tokens->{$_}->path_query
|
||||||
for qw/search_node search_device device_ports/;
|
for qw/search_node search_device device_ports/;
|
||||||
|
|||||||
@@ -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 {
|
get '/ajax/content/report/ipinventory' => require_login sub {
|
||||||
|
|
||||||
# Default to something simple with no results to prevent
|
# 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
|
# 'never' is true. TODO: Need better input validation, both JS and
|
||||||
# server-side to provide user feedback
|
# server-side to provide user feedback
|
||||||
$limit = 8192 if $limit > 8192;
|
$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(
|
my $rs1 = schema('netdisco')->resultset('DeviceIp')->search(
|
||||||
undef,
|
undef,
|
||||||
@@ -114,8 +96,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
|
|||||||
|
|
||||||
my $rs_sub = $rs_union->search(
|
my $rs_sub = $rs_union->search(
|
||||||
{ ip => { '<<' => $subnet->cidr } },
|
{ ip => { '<<' => $subnet->cidr } },
|
||||||
{ order_by => [qw( ip time_last )],
|
{ select => [
|
||||||
select => [
|
|
||||||
\'DISTINCT ON (ip) ip',
|
\'DISTINCT ON (ip) ip',
|
||||||
'dns',
|
'dns',
|
||||||
\qq/date_trunc('second', time_last) AS time_last/,
|
\qq/date_trunc('second', time_last) AS time_last/,
|
||||||
@@ -148,10 +129,16 @@ get '/ajax/content/report/ipinventory' => require_login sub {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$rs = $rs_union->search(
|
$rs = $rs_union->search(
|
||||||
{ -and => [
|
{ -or => [
|
||||||
time_last => { '>=', $start },
|
-and => [
|
||||||
time_last => { '<=', $end },
|
time_first => undef,
|
||||||
]
|
time_last => undef,
|
||||||
|
],
|
||||||
|
-and => [
|
||||||
|
time_last => { '>=', $start },
|
||||||
|
time_last => { '<=', $end },
|
||||||
|
],
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{ from => { me => $rs_sub }, }
|
{ from => { me => $rs_sub }, }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="clearfix">
|
<div class="clearfix">
|
||||||
<input class="nd_side-input" id="daterange"
|
<input class="nd_side-input" id="daterange"
|
||||||
type="text" name="daterange" value="[% params.daterange | html_entity %]"/>
|
type="text" name="daterange" value="[%
|
||||||
|
(params.exists('daterange') ? params.daterange : to_daterange('30 days')) | html_entity %]"/>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
@@ -35,7 +36,8 @@
|
|||||||
<em class="muted">Limit:</em><br/>
|
<em class="muted">Limit:</em><br/>
|
||||||
<select id="nd_mac-format" class="nd_side-select" name="limit">
|
<select id="nd_mac-format" class="nd_side-select" name="limit">
|
||||||
[% FOREACH size IN [ '32', '64', '128', '256', '1024', '2048', '4096', '8192' ] %]
|
[% FOREACH size IN [ '32', '64', '128', '256', '1024', '2048', '4096', '8192' ] %]
|
||||||
<option[% ' selected="selected"' IF params.limit == size %]>[% size %]</option>
|
<option[% ' selected="selected"' IF (params.limit == size OR (NOT params.limit AND size == 256)) %]>
|
||||||
|
[% size %]</option>
|
||||||
[% END %]
|
[% END %]
|
||||||
</select>
|
</select>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user