From 279924d2fb90978d688307aa22826f15d24ad76e Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Mon, 3 Feb 2014 22:17:06 -0500 Subject: [PATCH] Correct date formatting and logic in IP Inventory report --- Netdisco/Changes | 1 + .../Netdisco/Web/Plugin/Report/IpInventory.pm | 25 +++++++++++-------- .../share/views/ajax/report/ipinventory.tt | 12 +-------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index a28f01ca..81bdde20 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -16,6 +16,7 @@ [BUG FIXES] * [#84] No longer use dns as a key into devices; cope with dupe dns (LT) + * Correct date formatting and logic in IP Inventory report 2.022000 - 2014-01-26 diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm index 467a2f6a..db826538 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm @@ -65,7 +65,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { 'dns', \'true AS active', \'false AS node', - \'age(device.last_discover) AS age' + \qq/replace( date_trunc( 'minute', age( now(), device.last_discover ) ) ::text, 'mon', 'month') AS age/ ], as => [qw( ip time_first time_last dns active node age)], } @@ -74,7 +74,9 @@ get '/ajax/content/report/ipinventory' => require_login sub { my $rs2 = schema('netdisco')->resultset('NodeIp')->search( undef, { columns => [qw( ip time_first time_last dns active)], - '+select' => [ \'true AS node', \'age(time_last) AS age' ], + '+select' => [ \'true AS node', + \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ + ], '+as' => [ 'node', 'age' ], } )->hri; @@ -84,7 +86,8 @@ get '/ajax/content/report/ipinventory' => require_login sub { { columns => [qw( ip time_first time_last )], '+select' => [ 'nbname AS dns', 'active', - \'true AS node', \'age(time_last) AS age' + \'true AS node', + \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ ], '+as' => [ 'dns', 'active', 'node', 'age' ], } @@ -99,7 +102,9 @@ get '/ajax/content/report/ipinventory' => require_login sub { undef, { bind => [ $subnet->cidr ], columns => [qw( ip time_first time_last dns active)], - '+select' => [ \'false AS node', \'age(time_last) AS age' ], + '+select' => [ \'false AS node', + \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ + ], '+as' => [ 'node', 'age' ], } )->hri; @@ -113,8 +118,8 @@ get '/ajax/content/report/ipinventory' => require_login sub { select => [ \'DISTINCT ON (ip) ip', 'dns', - \'date_trunc(\'second\', time_last) AS time_last', - \'date_trunc(\'second\', time_first) AS time_first', + \qq/date_trunc('second', time_last) AS time_last/, + \qq/date_trunc('second', time_first) AS time_first/, 'active', 'node', 'age' @@ -134,8 +139,8 @@ get '/ajax/content/report/ipinventory' => require_login sub { if ( $agenot ) { $rs = $rs_union->search( { -or => [ - time_first => [ { '<', $start }, undef ], - time_last => { '>', $end }, + time_first => [ undef ], + time_last => [ { '<', $start }, { '>', $end } ] ] }, { from => { me => $rs_sub }, } @@ -144,8 +149,8 @@ get '/ajax/content/report/ipinventory' => require_login sub { else { $rs = $rs_union->search( { -and => [ - time_first => { '>=', $start }, - time_last => { '<=', $end }, + time_last => { '>=', $start }, + time_last => { '<=', $end }, ] }, { from => { me => $rs_sub }, } diff --git a/Netdisco/share/views/ajax/report/ipinventory.tt b/Netdisco/share/views/ajax/report/ipinventory.tt index d285fc4e..fbd5d718 100644 --- a/Netdisco/share/views/ajax/report/ipinventory.tt +++ b/Netdisco/share/views/ajax/report/ipinventory.tt @@ -21,17 +21,7 @@ [% row.ip | html_entity %] [% END %] [% row.dns | html_entity %] - [% IF row.age %] - [% age = row.age.replace('mon', 'month') %] - [% IF age.match('(day|month|year)') %] - [% age = age.remove('(-)?\d{2}:\d{2}.*$') %] - [% ELSE %] - [% age = age.replace('(\d{2}:\d{2}):\d{2}(\.\d*)$', '$1') %] - [% END %] - [% ELSE %] - [% age = 'Never' %] - [% END %] - [% age | html_entity %] + [% row.age || 'Never' | html_entity %] [% row.time_first || 'Never' | html_entity %] [% END %]