From 6d55dcd923762ef0cf71a4e48920d059f37312ed Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Tue, 5 Nov 2013 21:01:29 -0500 Subject: [PATCH] Move device addresses without DNS query out of model as it is unlikely to be used outside of the report. --- .../lib/App/Netdisco/DB/ResultSet/Device.pm | 58 ------------------- .../Web/Plugin/Report/DeviceAddrNoDNS.pm | 17 ++++-- 2 files changed, 12 insertions(+), 63 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm index fbb13d67..e1cb7679 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -665,62 +665,4 @@ sub with_poestats_as_hashref { return \@return; } -=head2 address_nodns_as_hashref - -This is a modifier for C 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 of the device. - -=item location - -C of the device. - -=item contact - -C 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; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceAddrNoDNS.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceAddrNoDNS.pm index 4c6d0376..b7eb57e6 100644 --- a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceAddrNoDNS.pm +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceAddrNoDNS.pm @@ -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 }; } };