diff --git a/Netdisco/Changes b/Netdisco/Changes index 3bc52cf3..f4c86751 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -3,6 +3,7 @@ [ENHANCEMENTS] * Respect ignore_interfaces and i_ignore when detecting wrapped device uptime + * Try NodeIp OUI company name search if no node results found [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/NodeIp.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/NodeIp.pm index 2a514c48..f99d0f4f 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/NodeIp.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/NodeIp.pm @@ -18,6 +18,29 @@ my $search_attr = { join => 'oui' }; +=head1 with_times + +This is a modifier for any C (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}); diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm index 4d130871..80b4e0df 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Node.pm @@ -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' });