add device ports into mac "node" search
This commit is contained in:
@@ -49,9 +49,9 @@ __PACKAGE__->set_primary_key("mac", "switch", "port");
|
|||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sGGyKEfUkoIFVtmj1wnH7A
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sGGyKEfUkoIFVtmj1wnH7A
|
||||||
|
|
||||||
__PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device',
|
__PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device',
|
||||||
{ 'foreign.ip' => 'self.switch' } );
|
{ 'foreign.ip' => 'self.switch' }, { join_type => 'LEFT' } );
|
||||||
__PACKAGE__->belongs_to( device_port => 'Netdisco::DB::Result::DevicePort',
|
__PACKAGE__->belongs_to( device_port => 'Netdisco::DB::Result::DevicePort',
|
||||||
{ 'foreign.ip' => 'self.switch', 'foreign.port' => 'self.port' } );
|
{ '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.mac' => 'self.mac' } );
|
||||||
|
|
||||||
|
|||||||
25
Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm
Normal file
25
Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package Netdisco::DB::ResultSet::DevicePort;
|
||||||
|
use base 'DBIx::Class::ResultSet';
|
||||||
|
|
||||||
|
sub by_mac {
|
||||||
|
my ($set, $mac) = @_;
|
||||||
|
return $set unless $mac;
|
||||||
|
|
||||||
|
return $set->search(
|
||||||
|
{
|
||||||
|
'me.mac' => $mac,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
order_by => {'-desc' => 'me.creation'},
|
||||||
|
columns => [qw/ ip port device.dns /],
|
||||||
|
'+select' => [
|
||||||
|
\"to_char(me.creation, 'YYYY-MM-DD HH24:MI')",
|
||||||
|
],
|
||||||
|
'+as' => [qw/ creation /],
|
||||||
|
join => 'device',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
@@ -49,11 +49,15 @@ ajax '/ajax/content/search/node' => sub {
|
|||||||
->by_mac(param('archived'), $mac->as_IEEE);
|
->by_mac(param('archived'), $mac->as_IEEE);
|
||||||
return unless $ips->count;
|
return unless $ips->count;
|
||||||
|
|
||||||
my $ports = 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 $ports = schema('netdisco')->resultset('DevicePort')
|
||||||
|
->by_mac($mac->as_IEEE);
|
||||||
|
|
||||||
template 'ajax/node_by_mac.tt', {
|
template 'ajax/node_by_mac.tt', {
|
||||||
ips => $ips,
|
ips => $ips,
|
||||||
|
sightings => $sightings,
|
||||||
ports => $ports,
|
ports => $ports,
|
||||||
}, { layout => undef };
|
}, { layout => undef };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
[% SET first_row = 0 %]
|
[% SET first_row = 0 %]
|
||||||
[% END %]
|
[% END %]
|
||||||
[% WHILE (node = ports.next) %]
|
[% WHILE (node = sightings.next) %]
|
||||||
<tr>
|
<tr>
|
||||||
<td> </td>
|
<td> </td>
|
||||||
[% IF params.vendor %]
|
[% IF params.vendor %]
|
||||||
@@ -63,5 +63,21 @@
|
|||||||
[% END %]
|
[% END %]
|
||||||
</tr>
|
</tr>
|
||||||
[% END %]
|
[% END %]
|
||||||
|
[% WHILE (port = ports.next) %]
|
||||||
|
<tr>
|
||||||
|
<td> </td>
|
||||||
|
[% IF params.vendor %]
|
||||||
|
<td> </td>
|
||||||
|
[% END %]
|
||||||
|
<td>Switch Port</td>
|
||||||
|
<td><a href="/device?q=[% port.ip | url %]&port=[% port.port | url %]">[% port.ip %] [ [% port.port %] ]</a>
|
||||||
|
[% ' (' _ port.device.dns.remove(settings.domain_suffix) _ ')' IF port.device.dns %]
|
||||||
|
</td>
|
||||||
|
[% IF params.stamps %]
|
||||||
|
<td>[% port.creation %]</td>
|
||||||
|
<td>[% port.creation %]</td>
|
||||||
|
[% END %]
|
||||||
|
</tr>
|
||||||
|
[% END %]
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user