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
* Add BSD install notes
* Update IP Inventory to show MAC address and have working Last Used sort
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->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",

View File

@@ -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'}],

View File

@@ -660,3 +660,6 @@ div.nd_datatables-pager {
margin-left: 50px;
}
td.nd_nowrap {
white-space: nowrap;
}

View File

@@ -2,9 +2,9 @@
<thead>
<tr>
<th>Node</th>
<th>DNS</th>
<th>MAC Address</th>
<th class="nd_center-cell">DNS</th>
<th>Last Used</th>
<th>First Discovered</th>
</tr>
</thead>
</table>
@@ -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 = '<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',
"className": "nd_nowrap nd_center-cell",
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, {
"data": 'age',
"render": function(data, type, row, meta) {
if (type == 'display') {
return he.encode(data || 'Never');
}
}, {
"data": 'time_first',
"render": function(data, type, row, meta) {
return he.encode(data || 'Never');
else {
// so that sorting works correctly on this column
return row.time_last;
}
}
}
],

View File

@@ -33,22 +33,14 @@
<div class="clearfix">
<ul class="unstyled">
<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">
[% FOREACH size IN [ '32', '64', '128', '256', '1024', '2048', '4096', '8192' ] %]
<option[% ' selected="selected"' IF (params.limit == size OR (NOT params.limit AND size == 256)) %]>
[% 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 == 2048)) %]>
[% size %]</option>
[% END %]
</select>
</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>
<div class="clearfix input-prepend"
rel="tooltip" data-placement="left" data-offset="5" data-title="Applies to IPv4 Only">