more POD and fixing templates/code to cope with name changes
This commit is contained in:
@@ -66,11 +66,23 @@ __PACKAGE__->set_primary_key("port", "ip");
|
|||||||
|
|
||||||
=head1 RELATIONSHIPS
|
=head1 RELATIONSHIPS
|
||||||
|
|
||||||
|
=head2 device
|
||||||
|
|
||||||
|
Returns the Device table entry to which the given Port is related.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
__PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip');
|
||||||
|
|
||||||
=head2 nodes
|
=head2 nodes
|
||||||
|
|
||||||
Returns the set of Nodes whose MAC addresses are associated with this Device
|
Returns the set of Nodes whose MAC addresses are associated with this Device
|
||||||
Port.
|
Port.
|
||||||
|
|
||||||
|
Remember you can pass a filter to this method to find only active or inactive
|
||||||
|
nodes, but do take into account that both the C<node> and C<node_ip> tables
|
||||||
|
include independent C<active> fields.
|
||||||
|
|
||||||
=over 4
|
=over 4
|
||||||
|
|
||||||
=item *
|
=item *
|
||||||
@@ -84,8 +96,8 @@ will also be retrieved.
|
|||||||
|
|
||||||
=item *
|
=item *
|
||||||
|
|
||||||
The additional column C<time_last_age> is a preformatted value for the
|
The additional column C<time_last_age> is a preformatted value for the Node's
|
||||||
C<time_last> field, which reads as "X days/weeks/months/years" ago.
|
C<time_last> field, which reads as "X days/weeks/months/years".
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
@@ -107,14 +119,6 @@ __PACKAGE__->has_many( nodes => 'Netdisco::DB::Result::Node',
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
sub get_nodes {
|
|
||||||
my ($row, $archive) = @_;
|
|
||||||
return $row->nodes({
|
|
||||||
($archive ? (-or => [{'me.active' => 1}, {'me.active' => 0}])
|
|
||||||
: ('me.active' => 1))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
=head2 neighbor_alias
|
=head2 neighbor_alias
|
||||||
|
|
||||||
When a device port has an attached neighbor device, this relationship will
|
When a device port has an attached neighbor device, this relationship will
|
||||||
@@ -128,51 +132,10 @@ database.
|
|||||||
=cut
|
=cut
|
||||||
|
|
||||||
__PACKAGE__->belongs_to( neighbor_alias => 'Netdisco::DB::Result::DeviceIp',
|
__PACKAGE__->belongs_to( neighbor_alias => 'Netdisco::DB::Result::DeviceIp',
|
||||||
{
|
{ 'foreign.alias' => 'self.remote_ip' },
|
||||||
'foreign.alias' => 'self.remote_ip',
|
|
||||||
},
|
|
||||||
{ join_type => 'LEFT' },
|
{ join_type => 'LEFT' },
|
||||||
);
|
);
|
||||||
|
|
||||||
=head2 device
|
|
||||||
|
|
||||||
Returns the Device table entry to which the given Port is related.
|
|
||||||
|
|
||||||
=over 4
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
Additional columns C<last_discover_stamp>, C<last_macsuck_stamp>,
|
|
||||||
C<last_arpnip_stamp> provide preformatted timestamps of the C<last_discover>,
|
|
||||||
C<last_macsuck> and C<last_arpnip> fields.
|
|
||||||
|
|
||||||
=item *
|
|
||||||
|
|
||||||
The additional column C<uptime_age> provides a performatted value for the
|
|
||||||
device uptime which reads as "X days/weeks/months/years" ago.
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
__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_age
|
|
||||||
last_discover_stamp
|
|
||||||
last_macsuck_stamp
|
|
||||||
last_arpnip_stamp
|
|
||||||
/],
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
=head2 port_vlans_tagged
|
=head2 port_vlans_tagged
|
||||||
|
|
||||||
Returns a set of rows from the C<device_port_vlan> table relating to this
|
Returns a set of rows from the C<device_port_vlan> table relating to this
|
||||||
@@ -255,8 +218,11 @@ the database.
|
|||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
# FIXME make this more efficient by specifying the full join to DBIC
|
# make this more efficient by specifying the full join to DBIC?
|
||||||
sub neighbor { return eval { (shift)->neighbor_alias->device } }
|
sub neighbor {
|
||||||
|
my $row = shift;
|
||||||
|
return eval { $row->neighbor_alias->device || undef };
|
||||||
|
}
|
||||||
|
|
||||||
=head2 native_vlan
|
=head2 native_vlan
|
||||||
|
|
||||||
|
|||||||
@@ -132,4 +132,16 @@ between the date stamp and time stamp. That is:
|
|||||||
|
|
||||||
sub time_last_stamp { return (shift)->get_column('time_last_stamp') }
|
sub time_last_stamp { return (shift)->get_column('time_last_stamp') }
|
||||||
|
|
||||||
|
=head2 time_last_age
|
||||||
|
|
||||||
|
Formatted version of the C<time_last> field, accurate to the minute.
|
||||||
|
|
||||||
|
The format is in "X days/months/years" style, similar to:
|
||||||
|
|
||||||
|
1 year 4 months 05:46:00
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub time_last_age { return (shift)->get_column('time_last_age') }
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -99,10 +99,14 @@ ajax '/ajax/content/device/ports' => sub {
|
|||||||
or $_->is_free(param('age_num'), param('age_unit')) } $set->all ];
|
or $_->is_free(param('age_num'), param('age_unit')) } $set->all ];
|
||||||
|
|
||||||
return unless scalar @$results;
|
return unless scalar @$results;
|
||||||
|
my @active = (param('n_archived')
|
||||||
|
? (-or => [{'me.active' => 1}, {'me.active' => 0}])
|
||||||
|
: ('me.active' => 1));
|
||||||
|
|
||||||
content_type('text/html');
|
content_type('text/html');
|
||||||
template 'ajax/device/ports.tt', {
|
template 'ajax/device/ports.tt', {
|
||||||
results => $results,
|
results => $results,
|
||||||
|
archive_filter => {@active},
|
||||||
}, { layout => undef };
|
}, { layout => undef };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,19 +43,19 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Uptime</td>
|
<td>Uptime</td>
|
||||||
<td>[% d.uptime %]</td>
|
<td>[% d.uptime_age %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Last Discover</td>
|
<td>Last Discover</td>
|
||||||
<td>[% d.last_discover %]</td>
|
<td>[% d.last_discover_stamp %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Last Arpnip</td>
|
<td>Last Arpnip</td>
|
||||||
<td>[% d.last_arpnip %]</td>
|
<td>[% d.last_arpnip_stamp %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Last Macsuck</td>
|
<td>Last Macsuck</td>
|
||||||
<td>[% d.last_macsuck %]</td>
|
<td>[% d.last_macsuck_stamp %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Hardware Status</td>
|
<td>Hardware Status</td>
|
||||||
|
|||||||
@@ -94,11 +94,11 @@
|
|||||||
<br/> ([% row.remote_type %]) / ([% row.remote_id %])</a>
|
<br/> ([% row.remote_type %]) / ([% row.remote_id %])</a>
|
||||||
[% END %]
|
[% END %]
|
||||||
[% END %]
|
[% END %]
|
||||||
[% FOREACH node IN row.get_nodes(params.n_archived) %]
|
[% FOREACH node IN row.nodes(archive_filter) %]
|
||||||
[% '<br/>' IF row.remote_ip OR NOT loop.first %]
|
[% '<br/>' IF row.remote_ip OR NOT loop.first %]
|
||||||
[% '<span class="label warning">a</span> ' IF NOT node.active %]
|
[% '<span class="label warning">a</span> ' IF NOT node.active %]
|
||||||
<a href="[% uri_for('/search') %]?tab=node&q=[% node.mac | uri %]">[% node.mac %]</a>
|
<a href="[% uri_for('/search') %]?tab=node&q=[% node.mac | uri %]">[% node.mac %]</a>
|
||||||
[% ' (' _ node.time_last _ ')' IF params.n_age %]
|
[% ' (' _ node.time_last_age _ ')' IF params.n_age %]
|
||||||
[% IF params.n_ip %]
|
[% IF params.n_ip %]
|
||||||
[% FOREACH ip IN node.ips %]
|
[% FOREACH ip IN node.ips %]
|
||||||
<br/> [% '<span class="label warning">a</span> ' IF NOT ip.active %]
|
<br/> [% '<span class="label warning">a</span> ' IF NOT ip.active %]
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
</td>
|
</td>
|
||||||
[% IF params.stamps %]
|
[% IF params.stamps %]
|
||||||
<td>[% row.time_first_stamp %]</td>
|
<td>[% row.time_first_stamp %]</td>
|
||||||
<td>[% rw.time_last_stamp %]</td>
|
<td>[% row.time_last_stamp %]</td>
|
||||||
[% END %]
|
[% END %]
|
||||||
</tr>
|
</tr>
|
||||||
[% SET first_row = 0 %]
|
[% SET first_row = 0 %]
|
||||||
|
|||||||
Reference in New Issue
Block a user