tighen up mac node search to work for switchports, and vendor display
This commit is contained in:
		| @@ -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+$/ | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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')", | ||||
|         ], | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user