1package App::Netdisco::Web::Plugin::Report::VlanInventory; 2 3use Dancer ':syntax'; 4use Dancer::Plugin::DBIC; 5use Dancer::Plugin::Auth::Extensible; 6 7use App::Netdisco::Web::Plugin; 8 9register_report( 10 { category => 'VLAN', 11 tag => 'vlaninventory', 12 label => 'VLAN Inventory', 13 provides_csv => 1, 14 api_endpoint => 1, 15 } 16); 17 18get '/ajax/content/report/vlaninventory' => require_login sub { 19 my @results = schema('netdisco')->resultset('DeviceVlan')->search( 20 { 'me.description' => { '!=', 'NULL' }, 21 'me.vlan' => { '>' => 0 }, 22 'ports.vlan' => { '>' => 0 }, 23 }, 24 { join => { 'ports' => 'vlan' }, 25 select => [ 26 'me.vlan', 27 'me.description', 28 { count => { distinct => 'me.ip' } }, 29 { count => 'ports.vlan' } 30 ], 31 as => [qw/ vlan description dcount pcount /], 32 group_by => [qw/ me.vlan me.description /], 33 } 34 )->hri->all; 35 36 return unless scalar @results; 37 38 if ( request->is_ajax ) { 39 my $json = to_json (\@results); 40 template 'ajax/report/vlaninventory.tt', { results => $json }; 41 } 42 else { 43 header( 'Content-Type' => 'text/comma-separated-values' ); 44 template 'ajax/report/vlaninventory_csv.tt', { results => \@results }; 45 } 46}; 47 48true; 49