From d6985e25cd74e539622356e93a2d8b39b3270b24 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sun, 8 Jan 2012 18:29:38 +0000 Subject: [PATCH] add device ports into mac "node" search --- Netdisco/lib/Netdisco/DB/Result/Node.pm | 4 +-- .../lib/Netdisco/DB/ResultSet/DevicePort.pm | 25 +++++++++++++++++++ Netdisco/lib/Netdisco/Web.pm | 6 ++++- Netdisco/views/ajax/node_by_mac.tt | 18 ++++++++++++- 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm diff --git a/Netdisco/lib/Netdisco/DB/Result/Node.pm b/Netdisco/lib/Netdisco/DB/Result/Node.pm index de6c3e15..680720cb 100644 --- a/Netdisco/lib/Netdisco/DB/Result/Node.pm +++ b/Netdisco/lib/Netdisco/DB/Result/Node.pm @@ -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' } ); diff --git a/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm b/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm new file mode 100644 index 00000000..5b8a028a --- /dev/null +++ b/Netdisco/lib/Netdisco/DB/ResultSet/DevicePort.pm @@ -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; + diff --git a/Netdisco/lib/Netdisco/Web.pm b/Netdisco/lib/Netdisco/Web.pm index 14b05743..434f7c0e 100644 --- a/Netdisco/lib/Netdisco/Web.pm +++ b/Netdisco/lib/Netdisco/Web.pm @@ -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 }; } diff --git a/Netdisco/views/ajax/node_by_mac.tt b/Netdisco/views/ajax/node_by_mac.tt index df749a04..72e0e96e 100644 --- a/Netdisco/views/ajax/node_by_mac.tt +++ b/Netdisco/views/ajax/node_by_mac.tt @@ -46,7 +46,7 @@ [% SET first_row = 0 %] [% END %] - [% WHILE (node = ports.next) %] + [% WHILE (node = sightings.next) %]   [% IF params.vendor %] @@ -63,5 +63,21 @@ [% END %] [% END %] + [% WHILE (port = ports.next) %] + +   + [% IF params.vendor %] +   + [% END %] + Switch Port + [% port.ip %] [ [% port.port %] ] + [% ' (' _ port.device.dns.remove(settings.domain_suffix) _ ')' IF port.device.dns %] + + [% IF params.stamps %] + [% port.creation %] + [% port.creation %] + [% END %] + + [% END %]