Be more strict about Node Search matching ports/wifi within date range

This commit is contained in:
Oliver Gorwits
2015-03-07 14:02:52 +00:00
parent b98d75b01c
commit c68d0cc35c
4 changed files with 49 additions and 9 deletions

View File

@@ -8,6 +8,8 @@
[ENHANCEMENTS] [ENHANCEMENTS]
* Show page and total records number on DataTables tables * Show page and total records number on DataTables tables
* Be more strict about Node Search matching ports/wifi within date range
* Allow filtering out of Device Ports on Node (MAC) search
[BUG FIXES] [BUG FIXES]

View File

@@ -25,7 +25,7 @@ ajax '/ajax/content/search/node' => require_login sub {
my $mac = NetAddr::MAC->new(mac => $node); my $mac = NetAddr::MAC->new(mac => $node);
my @active = (param('archived') ? () : (-bool => 'active')); my @active = (param('archived') ? () : (-bool => 'active'));
my @times = (); my (@times, @wifitimes, @porttimes);
if ($start and $end) { if ($start and $end) {
$start = $start . ' 00:00:00'; $start = $start . ' 00:00:00';
$end = $end . ' 23:59:59'; $end = $end . ' 23:59:59';
@@ -34,12 +34,28 @@ ajax '/ajax/content/search/node' => require_login sub {
time_first => [ { '<', $start }, undef ], time_first => [ { '<', $start }, undef ],
time_last => { '>', $end }, time_last => { '>', $end },
]); ]);
@wifitimes = (-or => [
time_last => { '<', $start },
time_last => { '>', $end },
]);
@porttimes = (-or => [
creation => { '<', $start },
creation => { '>', $end },
]);
} }
else { else {
@times = (-and => [ @times = (-and => [
time_first => { '>=', $start }, time_first => { '>=', $start },
time_last => { '<=', $end }, time_last => { '<=', $end },
]); ]);
@wifitimes = (-and => [
time_last => { '>=', $start },
time_last => { '<=', $end },
]);
@porttimes = (-and => [
creation => { '>=', $start },
creation => { '<=', $end },
]);
} }
} }
@@ -85,11 +101,8 @@ ajax '/ajax/content/search/node' => require_login sub {
join => 'oui' join => 'oui'
}); });
my $ports = schema('netdisco')->resultset('DevicePort')
->search({ -and => [@where_mac] });
my $wireless = schema('netdisco')->resultset('NodeWireless')->search( my $wireless = schema('netdisco')->resultset('NodeWireless')->search(
{ -and => [@where_mac] }, { -and => [@where_mac, @wifitimes] },
{ order_by => { '-desc' => 'time_last' }, { order_by => { '-desc' => 'time_last' },
'+columns' => [ '+columns' => [
'oui.company', 'oui.company',
@@ -101,8 +114,10 @@ ajax '/ajax/content/search/node' => require_login sub {
} }
); );
if ($sightings->has_rows or $ips->has_rows my $rs_dp = schema('netdisco')->resultset('DevicePort');
or $ports->has_rows or $netbios->has_rows) { if ($sightings->has_rows or $ips->has_rows or $netbios->has_rows) {
my $ports = param('deviceports')
? $rs_dp->search({ -and => [@where_mac] }) : undef;
return template 'ajax/search/node_by_mac.tt', { return template 'ajax/search/node_by_mac.tt', {
ips => $ips, ips => $ips,
@@ -112,7 +127,20 @@ ajax '/ajax/content/search/node' => require_login sub {
netbios => $netbios, netbios => $netbios,
}, { layout => undef }; }, { layout => undef };
} }
else {
my $ports = param('deviceports')
? $rs_dp->search({ -and => [@where_mac, @porttimes] }) : undef;
if (defined $ports and $ports->has_rows) {
return template 'ajax/search/node_by_mac.tt', {
ips => $ips,
sightings => $sightings,
ports => $ports,
wireless => $wireless,
netbios => $netbios,
}, { layout => undef };
}
}
my $set = schema('netdisco')->resultset('NodeNbt') my $set = schema('netdisco')->resultset('NodeNbt')
->search_by_name({nbname => $likeval, @active, @times}); ->search_by_name({nbname => $likeval, @active, @times});
@@ -133,7 +161,7 @@ ajax '/ajax/content/search/node' => require_login sub {
# if the user selects Vendor search opt, then # if the user selects Vendor search opt, then
# we'll try the OUI company name as a fallback # we'll try the OUI company name as a fallback
if (not $set->has_rows and param('show_vendor')) { if (param('show_vendor') and not $set->has_rows) {
$set = schema('netdisco')->resultset('NodeIp') $set = schema('netdisco')->resultset('NodeIp')
->with_times ->with_times
->search( ->search(

View File

@@ -12,6 +12,7 @@ hook 'before' => sub {
# view settings for node options # view settings for node options
var('node_options' => [ var('node_options' => [
{ name => 'stamps', label => 'Time Stamps', default => 'on' }, { name => 'stamps', label => 'Time Stamps', default => 'on' },
{ name => 'deviceports', label => 'Device Ports', default => 'on' },
]); ]);
# view settings for device options # view settings for device options

View File

@@ -10,6 +10,15 @@
<span class="nd_searchcheckbox uneditable-input">Time Stamps</span> <span class="nd_searchcheckbox uneditable-input">Time Stamps</span>
</label> </label>
</div> </div>
<div class="clearfix input-prepend">
<label class="add-on">
<input type="checkbox" id="deviceports"
name="deviceports"[% ' checked="checked"' IF params.deviceports %]/>
</label>
<label class="nd_checkboxlabel" for="deviceports">
<span class="nd_searchcheckbox uneditable-input">Device Ports</span>
</label>
</div>
<div class="clearfix input-prepend"> <div class="clearfix input-prepend">
<label class="add-on"> <label class="add-on">
<input type="checkbox" id="show_vendor" <input type="checkbox" id="show_vendor"