diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm index 194e8d6c..483379d1 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm @@ -139,6 +139,16 @@ sub native_vlan { return eval { $row->native_port_vlan->vlan || undef }; }; +__PACKAGE__->belongs_to( oui => 'Netdisco::DB::Result::Oui', + sub { + my $args = shift; + return { + "$args->{foreign_alias}.oui" => + { '=' => \"substring(cast($args->{self_alias}.mac as varchar) for 8)" } + }; + } +); + sub is_free { my ($row, $num, $unit) = @_; return unless $num =~ m/^\d+$/ diff --git a/Netdisco/lib/Netdisco/DB/Result/Node.pm b/Netdisco/lib/Netdisco/DB/Result/Node.pm index bf34d51a..228bdbc4 100644 --- a/Netdisco/lib/Netdisco/DB/Result/Node.pm +++ b/Netdisco/lib/Netdisco/DB/Result/Node.pm @@ -54,5 +54,6 @@ __PACKAGE__->belongs_to( device_port => 'Netdisco::DB::Result::DevicePort', { 'foreign.ip' => 'self.switch', 'foreign.port' => 'self.port' }, { join_type => 'LEFT' } ); __PACKAGE__->has_many( ips => 'Netdisco::DB::Result::NodeIp', { 'foreign.mac' => 'self.mac', 'foreign.active' => 'self.active' } ); +__PACKAGE__->belongs_to( oui => 'Netdisco::DB::Result::Oui', 'oui' ); 1; diff --git a/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm b/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm index 862ffc72..0ad88d47 100644 --- a/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm +++ b/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm @@ -32,7 +32,6 @@ sub by_mac { }, { order_by => {'-desc' => 'me.creation'}, - columns => [qw/ ip port device.dns /], '+select' => [ \"to_char(me.creation, 'YYYY-MM-DD HH24:MI')", ], diff --git a/Netdisco/lib/Netdisco/Web.pm b/Netdisco/lib/Netdisco/Web.pm index aa1e7a29..98dd9720 100644 --- a/Netdisco/lib/Netdisco/Web.pm +++ b/Netdisco/lib/Netdisco/Web.pm @@ -25,7 +25,7 @@ hook 'before' => sub { # make hash lookups of query lists foreach my $opt (qw/model vendor os_ver/) { - my $p = (ref [] eq ref param($opt) ? param($opt) : (param($opt) ? param($opt) : [])); + my $p = (ref [] eq ref param($opt) ? param($opt) : (param($opt) ? [param($opt)] : [])); var("${opt}_lkp" => { map { $_ => 1 } @$p }); } @@ -198,16 +198,19 @@ ajax '/ajax/content/search/node' => sub { my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0); if (eval { $mac->as_IEEE }) { - my $ips = schema('netdisco')->resultset('NodeIp') - ->by_mac(param('archived'), $mac->as_IEEE); - return unless $ips->count; - my $sightings = schema('netdisco')->resultset('Node') ->by_mac(param('archived'), $mac->as_IEEE); + my $ips = schema('netdisco')->resultset('NodeIp') + ->by_mac(param('archived'), $mac->as_IEEE); + my $ports = schema('netdisco')->resultset('DevicePort') ->by_mac($mac->as_IEEE); + return unless $sightings->count + or $ips->count + or $ports->count; + template 'ajax/search/node_by_mac.tt', { ips => $ips, sightings => $sightings, @@ -300,7 +303,8 @@ get '/search' => sub { else { my $s = schema('netdisco'); if ($q =~ m{^[a-f0-9.:/]+$}i) { - if ($s->resultset('Device')->find($q)) { + if (NetAddr::IP::Lite->new($q) and + $s->resultset('Device')->find($q)) { params->{'tab'} = 'device'; } else { diff --git a/Netdisco/views/ajax/search/node_by_mac.tt b/Netdisco/views/ajax/search/node_by_mac.tt index 8f6ab594..f9b0d012 100644 --- a/Netdisco/views/ajax/search/node_by_mac.tt +++ b/Netdisco/views/ajax/search/node_by_mac.tt @@ -41,16 +41,29 @@ [% IF params.stamps %]