From 8d903c9fe1415e80c0ace752b3db545afcf48bad Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Thu, 26 Sep 2013 19:33:48 -0400 Subject: [PATCH] add device inventory by location report --- .../Web/Plugin/Report/DeviceByLocation.pm | 35 +++++++++++++++++ Netdisco/share/config.yml | 1 + .../views/ajax/report/devicebylocation.tt | 39 +++++++++++++++++++ .../views/ajax/report/devicebylocation_csv.tt | 12 ++++++ 4 files changed, 87 insertions(+) create mode 100644 Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceByLocation.pm create mode 100644 Netdisco/share/views/ajax/report/devicebylocation.tt create mode 100644 Netdisco/share/views/ajax/report/devicebylocation_csv.tt diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceByLocation.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceByLocation.pm new file mode 100644 index 00000000..24d01b99 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/Report/DeviceByLocation.pm @@ -0,0 +1,35 @@ +package App::Netdisco::Web::Plugin::Report::DeviceByLocation; + +use Dancer ':syntax'; +use Dancer::Plugin::DBIC; +use Dancer::Plugin::Auth::Extensible; + +use App::Netdisco::Web::Plugin; + +register_report( + { category => 'Device', + tag => 'devicebylocation', + label => 'By Location', + provides_csv => 1, + } +); + +get '/ajax/content/report/devicebylocation' => require_login sub { + my $set + = schema('netdisco')->resultset('Device') + ->search( {}, + { order_by => [qw/ location name ip vendor model /], } ); + return unless $set->count; + + if ( request->is_ajax ) { + template 'ajax/report/devicebylocation.tt', { results => $set, }, + { layout => undef }; + } + else { + header( 'Content-Type' => 'text/comma-separated-values' ); + template 'ajax/report/devicebylocation_csv.tt', { results => $set, }, + { layout => undef }; + } +}; + +true; diff --git a/Netdisco/share/config.yml b/Netdisco/share/config.yml index 90014b48..3b753507 100644 --- a/Netdisco/share/config.yml +++ b/Netdisco/share/config.yml @@ -37,6 +37,7 @@ web_plugins: - Report::ApChannelDist - Report::ApRadioChannelPower - Report::HalfDuplex + - Report::DeviceByLocation - Report::DuplexMismatch - Report::SsidInventory - Report::VlanInventory diff --git a/Netdisco/share/views/ajax/report/devicebylocation.tt b/Netdisco/share/views/ajax/report/devicebylocation.tt new file mode 100644 index 00000000..d7aa3b67 --- /dev/null +++ b/Netdisco/share/views/ajax/report/devicebylocation.tt @@ -0,0 +1,39 @@ + + + + + + + + + + + + [% WHILE (row = results.next) %] + [% NEXT UNLESS row.vendor AND row.model %] + + + + + + + + [% END %] + +
LocationDeviceSystem NameVendorModel
+ [% IF row.location %] + + [% row.location | html_entity %] + [% ELSE %] + [Not Set] + [% END %] + [% row.dns || row.ip | html_entity %] + [% row.name | html_entity %] + + + [% row.vendor | html_entity %] + + + [% row.model | html_entity %] +
+ diff --git a/Netdisco/share/views/ajax/report/devicebylocation_csv.tt b/Netdisco/share/views/ajax/report/devicebylocation_csv.tt new file mode 100644 index 00000000..fb81572d --- /dev/null +++ b/Netdisco/share/views/ajax/report/devicebylocation_csv.tt @@ -0,0 +1,12 @@ +[% USE CSV -%] +[% CSV.dump([ 'Location' 'Device' 'System Name' 'Vendor' 'Model' ]) %] + +[% WHILE (row = results.next) %] + [% mylist = [] %] + [% device = row.dns || row.ip %] + [% FOREACH col IN [ row.location device row.name row.vendor row.model ] %] + [% mylist.push(col) %] + [% END %] + [% CSV.dump(mylist) %] + +[% END %]