Update IP Inventory to show MAC address and have working Last Used sort

This commit is contained in:
Oliver Gorwits
2014-12-24 18:23:13 +00:00
parent 692482caa7
commit cceae236d1
6 changed files with 41 additions and 28 deletions

View File

@@ -4,6 +4,7 @@
* Request net-snmp-devel on Fedora/Red-Hat builds * Request net-snmp-devel on Fedora/Red-Hat builds
* Add BSD install notes * Add BSD install notes
* Update IP Inventory to show MAC address and have working Last Used sort
2.029014 - 2014-11-19 2.029014 - 2014-11-19

View File

@@ -12,6 +12,7 @@ __PACKAGE__->table('cidr_ips');
__PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL'); __PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
SELECT host(network (prefix) + sub.int)::inet AS ip, SELECT host(network (prefix) + sub.int)::inet AS ip,
NULL AS mac,
NULL::text AS dns, NULL::text AS dns,
NULL::timestamp AS time_first, NULL::timestamp AS time_first,
NULL::timestamp AS time_last, NULL::timestamp AS time_last,
@@ -28,6 +29,8 @@ ENDSQL
__PACKAGE__->add_columns( __PACKAGE__->add_columns(
"ip", "ip",
{ data_type => "inet", is_nullable => 0 }, { data_type => "inet", is_nullable => 0 },
"mac",
{ data_type => "macaddr", is_nullable => 1 },
"dns", "dns",
{ data_type => "text", is_nullable => 1 }, { data_type => "text", is_nullable => 1 },
"active", "active",

View File

@@ -28,20 +28,20 @@ get '/ajax/content/report/ipinventory' => require_login sub {
my ( $start, $end ) = param('daterange') =~ /(\d+-\d+-\d+)/gmx; my ( $start, $end ) = param('daterange') =~ /(\d+-\d+-\d+)/gmx;
my $limit = param('limit') || 256; my $limit = param('limit') || 256;
my $order = param('order') || 'IP';
my $never = param('never') || '0'; my $never = param('never') || '0';
my $order = [{-desc => 'age'}, {-asc => 'ip'}];
# We need a reasonable limit to prevent a potential DoS, especially if # We need a reasonable limit to prevent a potential DoS, especially if
# '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' ? {-asc => 'ip'} : [{-desc => 'age'}, {-asc => 'ip'}];
my $rs1 = schema('netdisco')->resultset('DeviceIp')->search( my $rs1 = schema('netdisco')->resultset('DeviceIp')->search(
undef, undef,
{ join => 'device', { join => 'device',
select => [ select => [
'alias AS ip', 'alias AS ip',
\'NULL as mac',
'creation AS time_first', 'creation AS time_first',
'device.last_discover AS time_last', 'device.last_discover AS time_last',
'dns', 'dns',
@@ -49,13 +49,13 @@ get '/ajax/content/report/ipinventory' => require_login sub {
\'false AS node', \'false AS node',
\qq/replace( date_trunc( 'minute', age( now(), device.last_discover ) ) ::text, 'mon', 'month') 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)], as => [qw( ip mac time_first time_last dns active node age)],
} }
)->hri; )->hri;
my $rs2 = schema('netdisco')->resultset('NodeIp')->search( my $rs2 = schema('netdisco')->resultset('NodeIp')->search(
undef, undef,
{ columns => [qw( ip time_first time_last dns active)], { columns => [qw( ip mac time_first time_last dns active)],
'+select' => [ \'true AS node', '+select' => [ \'true AS node',
\qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ \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( my $rs3 = schema('netdisco')->resultset('NodeNbt')->search(
undef, undef,
{ columns => [qw( ip time_first time_last )], { columns => [qw( ip mac time_first time_last )],
'+select' => [ '+select' => [
'nbname AS dns', 'active', 'nbname AS dns', 'active',
\'true AS node', \'true AS node',
@@ -83,7 +83,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
my $rs4 = schema('netdisco')->resultset('Virtual::CidrIps')->search( my $rs4 = schema('netdisco')->resultset('Virtual::CidrIps')->search(
undef, undef,
{ bind => [ $subnet->cidr ], { 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', '+select' => [ \'false AS node',
\qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/ \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 } }, { ip => { '<<' => $subnet->cidr } },
{ select => [ { select => [
\'DISTINCT ON (ip) ip', \'DISTINCT ON (ip) ip',
'mac',
'dns', 'dns',
\qq/date_trunc('second', time_last) AS time_last/, \qq/date_trunc('second', time_last) AS time_last/,
\qq/date_trunc('second', time_first) AS time_first/, \qq/date_trunc('second', time_first) AS time_first/,
@@ -106,7 +107,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
'age' 'age'
], ],
as => [ as => [
'ip', 'dns', 'time_last', 'time_first', 'ip', 'mac', 'dns', 'time_last', 'time_first',
'active', 'node', 'age' 'active', 'node', 'age'
], ],
order_by => [{-asc => 'ip'}, {-desc => 'active'}], order_by => [{-asc => 'ip'}, {-desc => 'active'}],

View File

@@ -656,7 +656,10 @@ form .clearfix.success input {
/* dataTables */ /* dataTables */
div.nd_datatables-pager { div.nd_datatables-pager {
float: left; float: left;
margin-left: 50px; margin-left: 50px;
} }
td.nd_nowrap {
white-space: nowrap;
}

View File

@@ -2,9 +2,9 @@
<thead> <thead>
<tr> <tr>
<th>Node</th> <th>Node</th>
<th>DNS</th> <th>MAC Address</th>
<th class="nd_center-cell">DNS</th>
<th>Last Used</th> <th>Last Used</th>
<th>First Discovered</th>
</tr> </tr>
</thead> </thead>
</table> </table>
@@ -31,20 +31,33 @@ $(document).ready(function() {
} }
return cell_str; 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 = '<a href="[% search_node %]&q=' + encodeURIComponent(data)
+ (row.active ? '' : '&archived=on') + '">' + he.encode(data)
+ (row.active ? '' : '&nbsp;<i class="icon-book text-warning"></i>&nbsp;') + '</a>';
}
return cell_str;
}
}, { }, {
"data": 'dns', "data": 'dns',
"className": "nd_nowrap nd_center-cell",
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return he.encode(data || ''); return he.encode(data || '');
} }
}, { }, {
"data": 'age', "data": 'age',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return he.encode(data || 'Never'); if (type == 'display') {
} return he.encode(data || 'Never');
}, { }
"data": 'time_first', else {
"render": function(data, type, row, meta) { // so that sorting works correctly on this column
return he.encode(data || 'Never'); return row.time_last;
}
} }
} }
], ],

View File

@@ -33,22 +33,14 @@
<div class="clearfix"> <div class="clearfix">
<ul class="unstyled"> <ul class="unstyled">
<li> <li>
<em class="muted">Limit:</em><br/> <em class="muted">Oldest records 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', '512', '1024', '2048', '4096', '8192' ] %]
<option[% ' selected="selected"' IF (params.limit == size OR (NOT params.limit AND size == 256)) %]> <option[% ' selected="selected"' IF (params.limit == size OR (NOT params.limit AND size == 2048)) %]>
[% size %]</option> [% size %]</option>
[% END %] [% END %]
</select> </select>
</li> </li>
<li>
<em class="muted">Order By:</em><br/>
<select id="nd_mac-format" class="nd_side-select" name="order">
[% FOREACH item IN [ 'IP', 'Age' ] %]
<option[% ' selected="selected"' IF params.order == item %]>[% item %]</option>
[% END %]
</select>
</li>
</ul> </ul>
<div class="clearfix input-prepend" <div class="clearfix input-prepend"
rel="tooltip" data-placement="left" data-offset="5" data-title="Applies to IPv4 Only"> rel="tooltip" data-placement="left" data-offset="5" data-title="Applies to IPv4 Only">