From a16f8b401949db38ab57b5b6e8b2526d916d4628 Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Tue, 5 Nov 2013 17:51:06 -0500 Subject: [PATCH] Add Device addresses with DNS entries report --- Netdisco/Changes | 1 + .../lib/App/Netdisco/DB/ResultSet/Device.pm | 58 +++++++++++++++++++ .../Web/Plugin/Report/DeviceAddrNoDNS.pm | 35 +++++++++++ Netdisco/share/config.yml | 1 + .../views/ajax/report/deviceaddrnodns.tt | 21 +++++++ .../views/ajax/report/deviceaddrnodns_csv.tt | 12 ++++ 6 files changed, 128 insertions(+) create mode 100644 Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceAddrNoDNS.pm create mode 100644 Netdisco/share/views/ajax/report/deviceaddrnodns.tt create mode 100644 Netdisco/share/views/ajax/report/deviceaddrnodns_csv.tt diff --git a/Netdisco/Changes b/Netdisco/Changes index 6c6af16f..b019cc3c 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -3,6 +3,7 @@ [NEW FEATURES] * Add Device PoE status report * Add Nodes with multiple IP addresses report + * Add Device addresses with DNS entries report [ENHANCEMENTS] diff --git a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm index e1cb7679..fbb13d67 100644 --- a/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm +++ b/Netdisco/lib/App/Netdisco/DB/ResultSet/Device.pm @@ -665,4 +665,62 @@ 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 new file mode 100644 index 00000000..4c6d0376 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceAddrNoDNS.pm @@ -0,0 +1,35 @@ +package App::Netdisco::Web::Plugin::Report::DeviceAddrNoDNS; + +use Dancer ':syntax'; +use Dancer::Plugin::DBIC; +use Dancer::Plugin::Auth::Extensible; + +use App::Netdisco::Web::Plugin; + +register_report( + { category => 'Device', + tag => 'deviceaddrnodns', + label => 'Addresses without DNS Entries', + provides_csv => 1, + } +); + +get '/ajax/content/report/deviceaddrnodns' => require_login sub { + my $results = schema('netdisco')->resultset('Device') + ->address_nodns_as_hashref; + + return unless scalar $results; + + if ( request->is_ajax ) { + 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, }, + { layout => undef }; + } +}; + +1; diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index 7fd73b16..a6193b95 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -37,6 +37,7 @@ web_plugins: - Report::ApChannelDist - Report::ApRadioChannelPower - Report::HalfDuplex + - Report::DeviceAddrNoDNS - Report::DeviceByLocation - Report::DevicePoeStatus - Report::DuplexMismatch diff --git a/Netdisco/share/views/ajax/report/deviceaddrnodns.tt b/Netdisco/share/views/ajax/report/deviceaddrnodns.tt new file mode 100644 index 00000000..f572ccc0 --- /dev/null +++ b/Netdisco/share/views/ajax/report/deviceaddrnodns.tt @@ -0,0 +1,21 @@ + + + + + + + + + + + [% FOREACH row IN results %] + + + + + + [% END %] + +
DeviceAddressContactLocation
+ [% row.dns || row.name || row.ip | html_entity %] + [% row.alias | html_entity %][% row.contact | html_entity %][% row.location | html_entity %]
\ No newline at end of file diff --git a/Netdisco/share/views/ajax/report/deviceaddrnodns_csv.tt b/Netdisco/share/views/ajax/report/deviceaddrnodns_csv.tt new file mode 100644 index 00000000..4414afbf --- /dev/null +++ b/Netdisco/share/views/ajax/report/deviceaddrnodns_csv.tt @@ -0,0 +1,12 @@ +[% USE CSV -%] +[% CSV.dump([ 'Device' 'Address' 'Contact' 'Location' ]) %] + +[% FOREACH row IN results %] + [% mylist = [] %] + [% mylist.push(row.dns || row.name || row.ip) %] + [% mylist.push(row.alias) %] + [% mylist.push(row.contact) %] + [% mylist.push(row.location) %] + [% CSV.dump(mylist) %] + +[% END %]