« blib/lib/App/Netdisco/Web/Plugin/Report/Netbios.pm
↑ Summary
blib/lib/App/Netdisco/Web/Plugin/Report/NodeVendor.pm »
| 1 | package App::Netdisco::Web::Plugin::Report::NodeMultiIPs; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use Dancer::Plugin::DBIC; | ||
| 5 | use Dancer::Plugin::Auth::Extensible; | ||
| 6 | |||
| 7 | use App::Netdisco::Web::Plugin; | ||
| 8 | |||
| 9 | register_report( | ||
| 10 | { category => 'Node', | ||
| 11 | tag => 'nodemultiips', | ||
| 12 | label => 'Nodes with multiple active IP addresses', | ||
| 13 | provides_csv => 1, | ||
| 14 | api_endpoint => 1, | ||
| 15 | } | ||
| 16 | ); | ||
| 17 | |||
| 18 | get '/ajax/content/report/nodemultiips' => require_login sub { | ||
| 19 | my @results = schema(vars->{'tenant'})->resultset('Node')->search( | ||
| 20 | {}, | ||
| 21 | { select => [ 'mac', 'switch', 'port' ], | ||
| 22 | join => [qw/device ips manufacturer/], | ||
| 23 | '+columns' => [ | ||
| 24 | { 'dns' => 'device.dns' }, | ||
| 25 | { 'name' => 'device.name' }, | ||
| 26 | { 'ip_count' => { count => 'ips.ip' } }, | ||
| 27 | { 'vendor' => 'manufacturer.company' } | ||
| 28 | ], | ||
| 29 | group_by => [ | ||
| 30 | qw/ me.mac me.switch me.port device.dns device.name manufacturer.company/ | ||
| 31 | ], | ||
| 32 | having => \[ 'count(ips.ip) > ?', [ count => 1 ] ], | ||
| 33 | order_by => { -desc => [qw/count/] }, | ||
| 34 | } | ||
| 35 | )->hri->all; | ||
| 36 | |||
| 37 | return unless scalar @results; | ||
| 38 | |||
| 39 | if ( request->is_ajax ) { | ||
| 40 | my $json = to_json( \@results ); | ||
| 41 | template 'ajax/report/nodemultiips.tt', { results => $json }, { layout => 'noop' }; | ||
| 42 | } | ||
| 43 | else { | ||
| 44 | header( 'Content-Type' => 'text/comma-separated-values' ); | ||
| 45 | template 'ajax/report/nodemultiips_csv.tt', | ||
| 46 | { results => \@results }, { layout => 'noop' }; | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | |||
| 50 | 1; |