Move device addresses without DNS query out of model as it is unlikely to be used outside of the report.

This commit is contained in:
Eric A. Miller
2013-11-05 21:01:29 -05:00
parent a16f8b4019
commit 6d55dcd923
2 changed files with 12 additions and 63 deletions

View File

@@ -665,62 +665,4 @@ sub with_poestats_as_hashref {
return \@return;
}
=head2 address_nodns_as_hashref
This is a modifier for C<search()> which returns a list of hash references
for devices addresses without a corresponding DNS entry.
Note: The DNS resolver checks both reverse and forward entries of the
address. Verify reverse and forward DNS entries if it appears an address
was included erroneously.
Returned hash keys:
=over 4
=item ip
The primary IP address of the device.
=item dns
DNS entry of primary IP address of the device.
=item name
C<sysName> of the device.
=item location
C<sysLocation> of the device.
=item contact
C<sysContact> of the device.
=item alias
IP address belonging to the device without a corresponding DNS
entry.
=back
=cut
sub address_nodns_as_hashref {
my ( $rs, $cond, $attrs ) = @_;
my @return = $rs->search(
{ 'device_ips.dns' => undef },
{ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
select => [ 'ip', 'dns', 'name', 'location', 'contact' ],
join => [qw/device_ips/],
'+columns' => [ { 'alias' => 'device_ips.alias' }, ],
order_by => { -asc => [qw/me.ip device_ips.alias/] },
}
)->all;
return \@return;
}
1;

View File

@@ -15,19 +15,26 @@ register_report(
);
get '/ajax/content/report/deviceaddrnodns' => require_login sub {
my $results = schema('netdisco')->resultset('Device')
->address_nodns_as_hashref;
my @results = schema('netdisco')->resultset('Device')->search(
{ 'device_ips.dns' => undef },
{ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
select => [ 'ip', 'dns', 'name', 'location', 'contact' ],
join => [qw/device_ips/],
'+columns' => [ { 'alias' => 'device_ips.alias' }, ],
order_by => { -asc => [qw/me.ip device_ips.alias/] },
}
)->all;
return unless scalar $results;
return unless scalar @results;
if ( request->is_ajax ) {
template 'ajax/report/deviceaddrnodns.tt', { results => $results, },
template 'ajax/report/deviceaddrnodns.tt', { results => \@results, },
{ layout => undef };
}
else {
header( 'Content-Type' => 'text/comma-separated-values' );
template 'ajax/report/deviceaddrnodns_csv.tt',
{ results => $results, },
{ results => \@results, },
{ layout => undef };
}
};