add device ports into mac "node" search

This commit is contained in:
Oliver Gorwits
2012-01-08 18:29:38 +00:00
parent 51c88eefdc
commit d6985e25cd
4 changed files with 49 additions and 4 deletions

View File

@@ -49,9 +49,9 @@ __PACKAGE__->set_primary_key("mac", "switch", "port");
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sGGyKEfUkoIFVtmj1wnH7A
__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',
{ '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',
{ 'foreign.mac' => 'self.mac' } );

View 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;

View File

@@ -49,11 +49,15 @@ ajax '/ajax/content/search/node' => sub {
->by_mac(param('archived'), $mac->as_IEEE);
return unless $ips->count;
my $ports = schema('netdisco')->resultset('Node')
my $sightings = schema('netdisco')->resultset('Node')
->by_mac(param('archived'), $mac->as_IEEE);
my $ports = schema('netdisco')->resultset('DevicePort')
->by_mac($mac->as_IEEE);
template 'ajax/node_by_mac.tt', {
ips => $ips,
sightings => $sightings,
ports => $ports,
}, { layout => undef };
}

View File

@@ -46,7 +46,7 @@
</tr>
[% SET first_row = 0 %]
[% END %]
[% WHILE (node = ports.next) %]
[% WHILE (node = sightings.next) %]
<tr>
<td>&nbsp;</td>
[% IF params.vendor %]
@@ -63,5 +63,21 @@
[% END %]
</tr>
[% END %]
[% WHILE (port = ports.next) %]
<tr>
<td>&nbsp;</td>
[% IF params.vendor %]
<td>&nbsp;</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>
</table>