diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm index 9e7b7055..d71a2231 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm @@ -64,16 +64,48 @@ __PACKAGE__->set_primary_key("port", "ip"); # Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:lcbweb0loNwHoWUuxTN/hA +__PACKAGE__->has_many( nodes => 'Netdisco::DB::Result::Node', + { + 'foreign.switch' => 'self.ip', + 'foreign.port' => 'self.port', + }, + { + prefetch => 'ips', + order_by => 'me.mac', + '+select' => [ + \"replace(age(me.time_last, me.time_recent)::text, 'mon', 'month')", + ], + '+as' => [ + 'me.time_last', + ], + }, +); + +sub get_nodes { + my ($row, $archive) = @_; + return $row->nodes({ ($archive ? () : ('me.active' => 1, 'ips.active' => 1)) }); +} + +__PACKAGE__->belongs_to( neighbor_alias => 'Netdisco::DB::Result::DeviceIp', + { + 'foreign.alias' => 'self.remote_ip', + }, + { + join_type => 'left', + }, +); +# FIXME make this more efficient by specifying the full join to DBIC +sub neighbor { return eval { (shift)->neighbor_alias->device } } __PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip', - { - '+select' => [ - \"replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')", - \"to_char(last_discover, 'YYYY-MM-DD HH24:MI')", - \"to_char(last_macsuck, 'YYYY-MM-DD HH24:MI')", - \"to_char(last_arpnip, 'YYYY-MM-DD HH24:MI')", - ], - '+as' => [qw/ uptime last_discover last_macsuck last_arpnip /], - }, + { + '+select' => [ + \"replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')", + \"to_char(last_discover, 'YYYY-MM-DD HH24:MI')", + \"to_char(last_macsuck, 'YYYY-MM-DD HH24:MI')", + \"to_char(last_arpnip, 'YYYY-MM-DD HH24:MI')", + ], + '+as' => [qw/ uptime last_discover last_macsuck last_arpnip /], + }, ); __PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan', { diff --git a/Netdisco/views/ajax/device/ports.tt b/Netdisco/views/ajax/device/ports.tt index 2bbd8654..29bdd202 100644 --- a/Netdisco/views/ajax/device/ports.tt +++ b/Netdisco/views/ajax/device/ports.tt @@ -3,8 +3,8 @@ [% FOREACH item IN vars.port_columns %] - [% NEXT UNLESS params.${item.name} %] - [% item.label %] + [% NEXT UNLESS params.${item.name} %] + [% item.label %] [% END %] @@ -74,15 +74,44 @@ [% SET count = count + 1 %] [% END %] [% IF count > 10 %] - [% SET output = '
(' _ count _ ')
' - _ 'Show VLANs
' _ output %] - [% SET output = output _ '
' %] + [% SET output = '
(' _ count _ ')
' + _ 'Show VLANs
' _ output %] + [% SET output = output _ '
' %] [% END %] [% output %] [% END %] [% IF params.c_connected %] - [% row.connected | html_entity %] + + [% IF row.remote_ip %] + [% IF row.neighbor %] + + [% row.neighbor.dns.remove(settings.domain_suffix) || row.neighbor.ip %] + ([% row.remote_port | html_entity %]) + [% ELSE %] + n + [% row.remote_ip %] ([% row.remote_port %]) +
  ([% row.remote_type %]) / ([% row.remote_id %]
+ [% END %] + [% END %] + [% FOREACH node IN row.get_nodes(params.n_archived) %] + [% '
' IF row.remote_ip OR NOT loop.first %] + [% 'a  ' IF NOT node.active %] + [% node.mac %] + [% ' (' _ node.time_last _ ')' IF params.n_age %] + [% IF params.n_ip %] + [% FOREACH ip IN node.ips %] +
  [% 'a  ' IF NOT node.active %] + [% SET dns = ip.dns %] + [% IF dns %] + [% ip.dns %] ([% ip.ip %]) + [% ELSE %] + [% ip.ip %] + [% END %] + [% END %] + [% END %] + [% END %] + [% END %] [% IF params.c_stp %] [% row.stp | html_entity %]