From 8d82023ac62eaf5530e7afc63f5102287c750c48 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 22 Feb 2018 21:31:17 +0000 Subject: [PATCH] implement system_reports and convert PortErrorDisabled to system report --- lib/App/Netdisco/Configuration.pm | 3 ++ .../Web/Plugin/Report/PortErrorDisabled.pm | 49 ------------------- share/config.yml | 17 +++++++ 3 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 lib/App/Netdisco/Web/Plugin/Report/PortErrorDisabled.pm diff --git a/lib/App/Netdisco/Configuration.pm b/lib/App/Netdisco/Configuration.pm index 32b324e0..792ae39e 100644 --- a/lib/App/Netdisco/Configuration.pm +++ b/lib/App/Netdisco/Configuration.pm @@ -194,4 +194,7 @@ if (setting('reports') and ref {} eq ref setting('reports')) { }} keys %{ setting('reports') } ]; } +# add system_reports onto reports +config->{'reports'} = [ @{setting('system_reports')}, @{setting('reports')} ]; + true; diff --git a/lib/App/Netdisco/Web/Plugin/Report/PortErrorDisabled.pm b/lib/App/Netdisco/Web/Plugin/Report/PortErrorDisabled.pm deleted file mode 100644 index 3543146f..00000000 --- a/lib/App/Netdisco/Web/Plugin/Report/PortErrorDisabled.pm +++ /dev/null @@ -1,49 +0,0 @@ -package App::Netdisco::Web::Plugin::Report::PortErrorDisabled; - -use Dancer ':syntax'; -use Dancer::Plugin::DBIC; -use Dancer::Plugin::Auth::Extensible; - -use App::Netdisco::Web::Plugin; - -register_report( - { category => 'Port', - tag => 'porterrordisabled', - label => 'Error Disabled Ports', - provides_csv => 1, - } -); - -get '/ajax/content/report/porterrordisabled' => require_login sub { - my @results = schema('netdisco')->resultset('DevicePorts') - ->with_properties->search({ - 'properties.error_disable_cause' => { '!=' => undef }, - })->hri->all; -# { select => [ 'ip', 'dns', 'name' ], -# join => { 'ports' => [ 'wireless', 'nodes' ] }, -# '+columns' => [ -# { 'port' => 'ports.port' }, -# { 'description' => 'ports.name' }, -# { 'mac_count' => { count => 'nodes.mac' } }, -# ], -# group_by => [qw/me.ip me.dns me.name ports.port ports.name/], -# having => \[ 'count(nodes.mac) > ?', [ count => 1 ] ], -# order_by => { -desc => [qw/count/] }, -# } - - return unless scalar @results; - - if ( request->is_ajax ) { - my $json = to_json (\@results); - template 'ajax/report/porterrordisabled.tt', { results => $json }, - { layout => undef }; - } - else { - header( 'Content-Type' => 'text/comma-separated-values' ); - template 'ajax/report/porterrordisabled.tt', - { results => \@results, }, - { layout => undef }; - } -}; - -1; diff --git a/share/config.yml b/share/config.yml index 94d02426..bacea941 100644 --- a/share/config.yml +++ b/share/config.yml @@ -148,6 +148,23 @@ device_port_col_idx_right: -1 jobqueue_refresh: 10 safe_password_store: true reports: [] +system_reports: + - tag: portserrordisabled + label: 'Error Disabled Ports' + category: Port + columns: + - { ip: Device } + - { dns: DNS } + - { port: Port } + - { name: Description } + - { reason: Reason } + query: | + SELECT dp.ip, d.dns, dp.port, dp.name, properties.error_disable_cause AS reason + FROM device_port dp + INNER JOIN device_port_properties properties USING (ip, port) + LEFT JOIN device d USING (ip) + WHERE properties.error_disable_cause IS NOT NULL + ORDER BY dp.ip, dp.port table_pagesize: 10 table_showrecordsmenu: - [10, 25, 50, 100, '-1']