From e23c30f0bebe5f06b44d187713e4958e952ffdcc Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Sun, 26 Jan 2014 20:50:01 -0500 Subject: [PATCH] [#74] Device Name / DNS mismatches report --- Netdisco/Changes | 1 + .../DB/Result/Virtual/DeviceDnsMismatch.pm | 25 +++++++++++++ .../Web/Plugin/Report/DeviceDnsMismatch.pm | 37 +++++++++++++++++++ Netdisco/share/config.yml | 1 + .../views/ajax/report/devicednsmismatch.tt | 23 ++++++++++++ .../ajax/report/devicednsmismatch_csv.tt | 13 +++++++ 6 files changed, 100 insertions(+) create mode 100644 Netdisco/lib/App/Netdisco/DB/Result/Virtual/DeviceDnsMismatch.pm create mode 100644 Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceDnsMismatch.pm create mode 100644 Netdisco/share/views/ajax/report/devicednsmismatch.tt create mode 100644 Netdisco/share/views/ajax/report/devicednsmismatch_csv.tt diff --git a/Netdisco/Changes b/Netdisco/Changes index 3abfb324..eeab1a21 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -3,6 +3,7 @@ [NEW FEATURES] * [#86] Use Vendor abbrevs to enhance node display in device port view + * [#74] Device Name / DNS mismatches report [ENHANCEMENTS] diff --git a/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DeviceDnsMismatch.pm b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DeviceDnsMismatch.pm new file mode 100644 index 00000000..71ac29a1 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/DB/Result/Virtual/DeviceDnsMismatch.pm @@ -0,0 +1,25 @@ +package App::Netdisco::DB::Result::Virtual::DeviceDnsMismatch; + +use strict; +use warnings; + +use utf8; +use base 'App::Netdisco::DB::Result::Device'; + +__PACKAGE__->load_components('Helper::Row::SubClass'); +__PACKAGE__->subclass; + +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); +__PACKAGE__->table('device_dns_mismatch'); +__PACKAGE__->result_source_instance->is_virtual(1); +__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL'); +SELECT * +FROM device +WHERE dns IS NULL + OR name IS NULL + OR lower(trim(TRAILING ? + FROM dns)::text) != lower(trim(TRAILING ? + FROM name)::text) +ENDSQL + +1; diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceDnsMismatch.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceDnsMismatch.pm new file mode 100644 index 00000000..4aec2b25 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceDnsMismatch.pm @@ -0,0 +1,37 @@ +package App::Netdisco::Web::Plugin::Report::DeviceDnsMismatch; + +use Dancer ':syntax'; +use Dancer::Plugin::DBIC; +use Dancer::Plugin::Auth::Extensible; + +use App::Netdisco::Web::Plugin; + +register_report( + { category => 'Device', + tag => 'devicednsmismatch', + label => 'Device Name / DNS Mismatches', + provides_csv => 1, + } +); + +get '/ajax/content/report/devicednsmismatch' => require_login sub { + + my $suffix = setting('domain_suffix') || ''; + + my $rs = schema('netdisco')->resultset('Virtual::DeviceDnsMismatch') + ->search( undef, { bind => [ $suffix, $suffix ] } ); + + return unless $rs->has_rows; + + if ( request->is_ajax ) { + template 'ajax/report/devicednsmismatch.tt', { results => $rs, }, + { layout => undef }; + } + else { + header( 'Content-Type' => 'text/comma-separated-values' ); + template 'ajax/report/devicednsmismatch_csv.tt', { results => $rs, }, + { layout => undef }; + } +}; + +1; diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index 3c7d09b3..863746a7 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -43,6 +43,7 @@ web_plugins: - Report::HalfDuplex - Report::DeviceAddrNoDNS - Report::DeviceByLocation + - Report::DeviceDnsMismatch - Report::DevicePoeStatus - Report::DuplexMismatch - Report::IpInventory diff --git a/Netdisco/share/views/ajax/report/devicednsmismatch.tt b/Netdisco/share/views/ajax/report/devicednsmismatch.tt new file mode 100644 index 00000000..07aeaa27 --- /dev/null +++ b/Netdisco/share/views/ajax/report/devicednsmismatch.tt @@ -0,0 +1,23 @@ + + + + + + + + + + + + [% WHILE (row = results.next) %] + + + + + + + [% END %] + +
NameDNSIP AddressContactLocation
+ [% row.name | html_entity %] + [% row.dns | html_entity %][% row.ip | html_entity %][% row.contact | html_entity %][% row.location | html_entity %]
\ No newline at end of file diff --git a/Netdisco/share/views/ajax/report/devicednsmismatch_csv.tt b/Netdisco/share/views/ajax/report/devicednsmismatch_csv.tt new file mode 100644 index 00000000..9dfbfe8b --- /dev/null +++ b/Netdisco/share/views/ajax/report/devicednsmismatch_csv.tt @@ -0,0 +1,13 @@ +[% USE CSV -%] +[% CSV.dump([ 'Name' 'DNS' 'IP Address' 'Contact' 'Location' ]) %] + +[% WHILE (row = results.next) %] + [% mylist = [] %] + [% mylist.push(row.name) %] + [% mylist.push(row.dns) %] + [% mylist.push(row.ip) %] + [% mylist.push(row.contact) %] + [% mylist.push(row.location) %] + [% CSV.dump(mylist) %] + +[% END %]