From cceae236d16b460fa5bb5380defb1033b6ca4728 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 24 Dec 2014 18:23:13 +0000 Subject: [PATCH] Update IP Inventory to show MAC address and have working Last Used sort --- Netdisco/Changes | 1 + .../App/Netdisco/DB/Result/Virtual/CidrIps.pm | 3 ++ .../Netdisco/Web/Plugin/Report/IpInventory.pm | 15 +++++----- Netdisco/share/public/css/netdisco.css | 7 +++-- .../share/views/ajax/report/ipinventory.tt | 29 ++++++++++++++----- .../share/views/sidebar/report/ipinventory.tt | 14 ++------- 6 files changed, 41 insertions(+), 28 deletions(-) diff --git a/Netdisco/Changes b/Netdisco/Changes index 5f725fb1..f0f19074 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -4,6 +4,7 @@ * Request net-snmp-devel on Fedora/Red-Hat builds * Add BSD install notes + * Update IP Inventory to show MAC address and have working Last Used sort 2.029014 - 2014-11-19 diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/CidrIps.pm b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/CidrIps.pm index 8cdbeff3..a5e9fdc8 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/CidrIps.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/CidrIps.pm @@ -12,6 +12,7 @@ __PACKAGE__->table('cidr_ips'); __PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL'); SELECT host(network (prefix) + sub.int)::inet AS ip, + NULL AS mac, NULL::text AS dns, NULL::timestamp AS time_first, NULL::timestamp AS time_last, @@ -28,6 +29,8 @@ ENDSQL __PACKAGE__->add_columns( "ip", { data_type => "inet", is_nullable => 0 }, + "mac", + { data_type => "macaddr", is_nullable => 1 }, "dns", { data_type => "text", is_nullable => 1 }, "active", diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm index 05decdbe..77469b97 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/IpInventory.pm @@ -28,20 +28,20 @@ get '/ajax/content/report/ipinventory' => require_login sub { my ( $start, $end ) = param('daterange') =~ /(\d+-\d+-\d+)/gmx; my $limit = param('limit') || 256; - my $order = param('order') || 'IP'; my $never = param('never') || '0'; + my $order = [{-desc => 'age'}, {-asc => 'ip'}]; # We need a reasonable limit to prevent a potential DoS, especially if # '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' ? {-asc => 'ip'} : [{-desc => 'age'}, {-asc => 'ip'}]; my $rs1 = schema('netdisco')->resultset('DeviceIp')->search( undef, { join => 'device', select => [ 'alias AS ip', + \'NULL as mac', 'creation AS time_first', 'device.last_discover AS time_last', 'dns', @@ -49,13 +49,13 @@ get '/ajax/content/report/ipinventory' => require_login sub { \'false AS node', \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)], + as => [qw( ip mac time_first time_last dns active node age)], } )->hri; my $rs2 = schema('netdisco')->resultset('NodeIp')->search( undef, - { columns => [qw( ip time_first time_last dns active)], + { columns => [qw( ip mac time_first time_last dns active)], '+select' => [ \'true AS node', \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ ], @@ -65,7 +65,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { my $rs3 = schema('netdisco')->resultset('NodeNbt')->search( undef, - { columns => [qw( ip time_first time_last )], + { columns => [qw( ip mac time_first time_last )], '+select' => [ 'nbname AS dns', 'active', \'true AS node', @@ -83,7 +83,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { my $rs4 = schema('netdisco')->resultset('Virtual::CidrIps')->search( undef, { bind => [ $subnet->cidr ], - columns => [qw( ip time_first time_last dns active)], + columns => [qw( ip mac time_first time_last dns active)], '+select' => [ \'false AS node', \qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ ], @@ -98,6 +98,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { { ip => { '<<' => $subnet->cidr } }, { select => [ \'DISTINCT ON (ip) ip', + 'mac', 'dns', \qq/date_trunc('second', time_last) AS time_last/, \qq/date_trunc('second', time_first) AS time_first/, @@ -106,7 +107,7 @@ get '/ajax/content/report/ipinventory' => require_login sub { 'age' ], as => [ - 'ip', 'dns', 'time_last', 'time_first', + 'ip', 'mac', 'dns', 'time_last', 'time_first', 'active', 'node', 'age' ], order_by => [{-asc => 'ip'}, {-desc => 'active'}], diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index d6010d59..d736bb83 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -656,7 +656,10 @@ form .clearfix.success input { /* dataTables */ div.nd_datatables-pager { - float: left; - margin-left: 50px; + float: left; + margin-left: 50px; } +td.nd_nowrap { + white-space: nowrap; +} diff --git a/Netdisco/share/views/ajax/report/ipinventory.tt b/Netdisco/share/views/ajax/report/ipinventory.tt index 53f859f7..7ff4a98f 100644 --- a/Netdisco/share/views/ajax/report/ipinventory.tt +++ b/Netdisco/share/views/ajax/report/ipinventory.tt @@ -2,9 +2,9 @@ Node - DNS + MAC Address + DNS Last Used - First Discovered @@ -31,20 +31,33 @@ $(document).ready(function() { } return cell_str; } + }, { + "data": 'mac', + "render": function(data, type, row, meta) { + var cell_str = he.encode(data || ''); + if (type == 'display' && data && row.time_last) { + cell_str = '' + he.encode(data) + + (row.active ? '' : '  ') + ''; + } + return cell_str; + } }, { "data": 'dns', + "className": "nd_nowrap nd_center-cell", "render": function(data, type, row, meta) { return he.encode(data || ''); } }, { "data": 'age', "render": function(data, type, row, meta) { - return he.encode(data || 'Never'); - } - }, { - "data": 'time_first', - "render": function(data, type, row, meta) { - return he.encode(data || 'Never'); + if (type == 'display') { + return he.encode(data || 'Never'); + } + else { + // so that sorting works correctly on this column + return row.time_last; + } } } ], diff --git a/Netdisco/share/views/sidebar/report/ipinventory.tt b/Netdisco/share/views/sidebar/report/ipinventory.tt index 4ddb88ba..d62f70b3 100644 --- a/Netdisco/share/views/sidebar/report/ipinventory.tt +++ b/Netdisco/share/views/sidebar/report/ipinventory.tt @@ -33,22 +33,14 @@