Try NodeIp OUI company name search if no node results found
This commit is contained in:
@@ -18,6 +18,29 @@ my $search_attr = {
|
||||
join => 'oui'
|
||||
};
|
||||
|
||||
=head1 with_times
|
||||
|
||||
This is a modifier for any C<search()> (including the helpers below) which
|
||||
will add the following additional synthesized columns to the result set:
|
||||
|
||||
=over 4
|
||||
|
||||
=item time_first_stamp
|
||||
|
||||
=item time_last_stamp
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub with_times {
|
||||
my ($rs, $cond, $attrs) = @_;
|
||||
|
||||
return $rs
|
||||
->search_rs({}, $search_attr)
|
||||
->search($cond, $attrs);
|
||||
}
|
||||
|
||||
=head1 search_by_ip( \%cond, \%attrs? )
|
||||
|
||||
my $set = $rs->search_by_ip({ip => '192.0.2.1', active => 1});
|
||||
|
||||
@@ -59,6 +59,18 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
}
|
||||
$set = schema('netdisco')->resultset('NodeIp')
|
||||
->search_by_dns({dns => $node, @active});
|
||||
|
||||
# if the user selects Vendor search opt, then
|
||||
# we'll try the OUI company name as a fallback
|
||||
if (not $set->count and param('show_vendor')) {
|
||||
$node = param('q');
|
||||
$set = schema('netdisco')->resultset('NodeIp')
|
||||
->with_times
|
||||
->search(
|
||||
{'oui.company' => { -ilike => "\%$node\%"}},
|
||||
{'prefetch' => 'oui'},
|
||||
);
|
||||
}
|
||||
}
|
||||
return unless $set and $set->count;
|
||||
$set = $set->search_rs({}, { order_by => 'me.mac' });
|
||||
|
||||
Reference in New Issue
Block a user