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 };
|
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 {
|
sub is_free {
|
||||||
my ($row, $num, $unit) = @_;
|
my ($row, $num, $unit) = @_;
|
||||||
return unless $num =~ m/^\d+$/
|
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' } );
|
{ 'foreign.ip' => 'self.switch', 'foreign.port' => 'self.port' }, { join_type => 'LEFT' } );
|
||||||
__PACKAGE__->has_many( ips => 'Netdisco::DB::Result::NodeIp',
|
__PACKAGE__->has_many( ips => 'Netdisco::DB::Result::NodeIp',
|
||||||
{ 'foreign.mac' => 'self.mac', 'foreign.active' => 'self.active' } );
|
{ 'foreign.mac' => 'self.mac', 'foreign.active' => 'self.active' } );
|
||||||
|
__PACKAGE__->belongs_to( oui => 'Netdisco::DB::Result::Oui', 'oui' );
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ sub by_mac {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
order_by => {'-desc' => 'me.creation'},
|
order_by => {'-desc' => 'me.creation'},
|
||||||
columns => [qw/ ip port device.dns /],
|
|
||||||
'+select' => [
|
'+select' => [
|
||||||
\"to_char(me.creation, 'YYYY-MM-DD HH24:MI')",
|
\"to_char(me.creation, 'YYYY-MM-DD HH24:MI')",
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ hook 'before' => sub {
|
|||||||
|
|
||||||
# make hash lookups of query lists
|
# make hash lookups of query lists
|
||||||
foreach my $opt (qw/model vendor os_ver/) {
|
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 });
|
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);
|
my $mac = Net::MAC->new(mac => $node, 'die' => 0, verbose => 0);
|
||||||
if (eval { $mac->as_IEEE }) {
|
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')
|
my $sightings = schema('netdisco')->resultset('Node')
|
||||||
->by_mac(param('archived'), $mac->as_IEEE);
|
->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')
|
my $ports = schema('netdisco')->resultset('DevicePort')
|
||||||
->by_mac($mac->as_IEEE);
|
->by_mac($mac->as_IEEE);
|
||||||
|
|
||||||
|
return unless $sightings->count
|
||||||
|
or $ips->count
|
||||||
|
or $ports->count;
|
||||||
|
|
||||||
template 'ajax/search/node_by_mac.tt', {
|
template 'ajax/search/node_by_mac.tt', {
|
||||||
ips => $ips,
|
ips => $ips,
|
||||||
sightings => $sightings,
|
sightings => $sightings,
|
||||||
@@ -300,7 +303,8 @@ get '/search' => sub {
|
|||||||
else {
|
else {
|
||||||
my $s = schema('netdisco');
|
my $s = schema('netdisco');
|
||||||
if ($q =~ m{^[a-f0-9.:/]+$}i) {
|
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';
|
params->{'tab'} = 'device';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -41,16 +41,29 @@
|
|||||||
</td>
|
</td>
|
||||||
[% IF params.stamps %]
|
[% IF params.stamps %]
|
||||||
<td>[% row.time_first %]</td>
|
<td>[% row.time_first %]</td>
|
||||||
<td>[% row.time_last %]</td>
|
<td>[% rw.time_last %]</td>
|
||||||
[% END %]
|
[% END %]
|
||||||
</tr>
|
</tr>
|
||||||
[% SET first_row = 0 %]
|
[% SET first_row = 0 %]
|
||||||
[% END %]
|
[% END %]
|
||||||
[% WHILE (node = sightings.next) %]
|
[% WHILE (node = sightings.next) %]
|
||||||
<tr>
|
<tr>
|
||||||
<td> </td>
|
<td>
|
||||||
|
[% IF first_row %]
|
||||||
|
<a class="nd_linkcell"
|
||||||
|
href="/search?[% vars.query_defaults.node %]&q=[% node.mac | uri %]">[% node.mac %]</a>
|
||||||
|
[% ELSE %]
|
||||||
|
|
||||||
|
[% END %]
|
||||||
|
</td>
|
||||||
[% IF params.vendor %]
|
[% IF params.vendor %]
|
||||||
<td> </td>
|
<td>
|
||||||
|
[% IF first_row %]
|
||||||
|
[% node.oui.company %]
|
||||||
|
[% ELSE %]
|
||||||
|
|
||||||
|
[% END %]
|
||||||
|
</td>
|
||||||
[% END %]
|
[% END %]
|
||||||
<td>Switch Port</td>
|
<td>Switch Port</td>
|
||||||
<td><a href="/device?tab=ports&ip=[% node.switch | url %]&q=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
|
<td><a href="/device?tab=ports&ip=[% node.switch | url %]&q=[% node.port | url %]">[% node.switch %] [ [% node.port %] ]</a>
|
||||||
@@ -62,12 +75,26 @@
|
|||||||
<td>[% node.time_last %]</td>
|
<td>[% node.time_last %]</td>
|
||||||
[% END %]
|
[% END %]
|
||||||
</tr>
|
</tr>
|
||||||
|
[% SET first_row = 0 %]
|
||||||
[% END %]
|
[% END %]
|
||||||
[% WHILE (port = ports.next) %]
|
[% WHILE (port = ports.next) %]
|
||||||
<tr>
|
<tr>
|
||||||
<td> </td>
|
<td>
|
||||||
|
[% IF first_row %]
|
||||||
|
<a class="nd_linkcell"
|
||||||
|
href="/search?[% vars.query_defaults.node %]&q=[% port.mac | uri %]">[% port.mac %]</a>
|
||||||
|
[% ELSE %]
|
||||||
|
|
||||||
|
[% END %]
|
||||||
|
</td>
|
||||||
[% IF params.vendor %]
|
[% IF params.vendor %]
|
||||||
<td> </td>
|
<td>
|
||||||
|
[% IF first_row %]
|
||||||
|
[% port.oui.company %]
|
||||||
|
[% ELSE %]
|
||||||
|
|
||||||
|
[% END %]
|
||||||
|
</td>
|
||||||
[% END %]
|
[% END %]
|
||||||
<td>Switch Port</td>
|
<td>Switch Port</td>
|
||||||
<td><a href="/device?tab=ports&ip=[% port.ip | url %]&q=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
|
<td><a href="/device?tab=ports&ip=[% port.ip | url %]&q=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
|
||||||
@@ -78,6 +105,7 @@
|
|||||||
<td>[% port.creation %]</td>
|
<td>[% port.creation %]</td>
|
||||||
[% END %]
|
[% END %]
|
||||||
</tr>
|
</tr>
|
||||||
|
[% SET first_row = 0 %]
|
||||||
[% END %]
|
[% END %]
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user