1package App::Netdisco::Web::Plugin::Report::PortBlocking;
2
3use Dancer ':syntax';
4use Dancer::Plugin::DBIC;
5use Dancer::Plugin::Auth::Extensible;
6
7use App::Netdisco::Web::Plugin;
8
9register_report(
10    {   category     => 'Port',
11        tag          => 'portblocking',
12        label        => 'Ports that are blocking',
13        provides_csv => 1,
14        api_endpoint => 1,
15    }
16);
17
18get '/ajax/content/report/portblocking' => require_login sub {
19    my @results = schema('netdisco')->resultset('Device')->search(
20        { 'stp' => [ 'blocking', 'broken' ], 'up' => { '!=', 'down' } },
21        {   select       => [ 'ip', 'dns', 'name' ],
22            join         => ['ports'],
23            '+columns'   => [
24                { 'port'        => 'ports.port' },
25                { 'description' => 'ports.name' },
26                { 'stp'         => 'ports.stp' },
27            ]
28        }
29    )->hri->all;
30
31    return unless scalar @results;
32
33    if ( request->is_ajax ) {
34        my $json = to_json (\@results);
35        template 'ajax/report/portblocking.tt', { results => $json };
36    }
37    else {
38        header( 'Content-Type' => 'text/comma-separated-values' );
39        template 'ajax/report/portblocking_csv.tt',
40            { results => \@results, };
41    }
42};
43
441;
45