Try NodeIp OUI company name search if no node results found

This commit is contained in:
Oliver Gorwits
2013-09-25 18:01:43 +01:00
parent cb88267717
commit b1bce3c535
3 changed files with 36 additions and 0 deletions

View File

@@ -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});

View File

@@ -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' });