diff --git a/Netdisco/Changes b/Netdisco/Changes index 36004b67..dcde77f2 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -3,6 +3,7 @@ [NEW FEATURES] * netdisco-sshcollector script to get ARP data on devices without SNMP (C. Ramseyer) + * Search device by CDP/LLDP advertised ID or Type 2.029005 - 2014-08-13 diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Device.pm b/Netdisco/lib/App/Netdisco/DB/Result/Device.pm index 19aefbc2..cb602726 100644 --- a/Netdisco/lib/App/Netdisco/DB/Result/Device.pm +++ b/Netdisco/lib/App/Netdisco/DB/Result/Device.pm @@ -177,6 +177,17 @@ __PACKAGE__->has_many( 'ip', { join_type => 'RIGHT' } ); +=head2 neighbor_ports + +Returns the set of ports on other devices which connect to this device + +=cut + +__PACKAGE__->has_many( + neighbor_ports => 'App::Netdisco::DB::Result::DevicePort', + { 'foreign.remote_ip' => 'self.ip' }, +); + =head2 community Returns the row from the community string table, if one exists. diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm index 79050cff..9feb1768 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -176,6 +176,14 @@ Will match exactly the C field, which is the operating sytem software ve Will match exactly the C (manufacturer). +=item neighbor_id + +Will match the device if it has advertised this ID to a CDP/LLDP neighbor. + +=item neighbor_type + +Will match the device if it has advertised this Type to a CDP/LLDP neighbor. + =item dns Can match any of the Device IP address aliases as a substring. @@ -234,6 +242,11 @@ sub search_by_field { ($p->{layers} ? ('me.layers' => { '-ilike' => "\%$layer_string" }) : ()), + ($p->{neighbor_id} ? ('neighbor_ports.remote_id' => + { '-ilike' => "\%$p->{neighbor_id}\%" }) : ()), + ($p->{neighbor_type} ? ('neighbor_ports.remote_type' => + { '-ilike' => "\%$p->{neighbor_type}\%" }) : ()), + ($p->{model} ? ('me.model' => { '-in' => $p->{model} }) : ()), ($p->{os_ver} ? ('me.os_ver' => @@ -256,8 +269,8 @@ sub search_by_field { }, { order_by => [qw/ me.dns me.ip /], - (($p->{dns} or $p->{ip}) ? ( - join => 'device_ips', + (($p->{dns} or $p->{ip} or $p->{neighbor_id} or $p->{neighbor_type}) ? ( + join => [qw/device_ips neighbor_ports/], distinct => 1, ) : ()), } diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm index ec78f7ea..8aaae657 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Search/Device.pm @@ -14,7 +14,8 @@ register_search_tab( # device with various properties or a default match-all get '/ajax/content/search/device' => require_login sub { my $has_opt = List::MoreUtils::any { param($_) } - qw/name location dns ip description model os_ver vendor layers/; + qw/name location dns ip description model os_ver vendor layers + neighbor_id neighbor_type/; my $rs; if ($has_opt) { diff --git a/Netdisco/share/views/sidebar/search/device.tt b/Netdisco/share/views/sidebar/search/device.tt index 97722f72..a65b7f48 100644 --- a/Netdisco/share/views/sidebar/search/device.tt +++ b/Netdisco/share/views/sidebar/search/device.tt @@ -41,6 +41,22 @@ type="text" name="description" value="[% params.description | html_entity %]" rel="tooltip" data-placement="left" data-offset="5" data-title="Description"/> +
+ + + +
+
+ + + +