API implementation (#712)
* initial v0 creator * working json api for generic reports * add require login * move report swagger into plugin, and set new default layout of noop * require proper role and also use new util func * start to tidy authn * some work on cleaning up web authn * clean up the authN checks * fix bug * fix the auth for api * fixes to json handling * set swagger sort order * enable most reports for api endpoints * fix doc * add paramters to reports * add missed report * allow api_parameters in reports config * reorganise api * add vlan search * add port search * make sure to enable layout processing * add device search * add v1 to api paths * add Node Search * support api_responses * add device object search; fix spurious ports field in device result class * handle some plugins just returning undef if search fails * errors from api seamlessley * fix error in date range default * more sensible default for prefix * change order of endpoints in swagger-ui * all db row classes can now TO_JSON * add device_port api endpoint * add device ports endpoint * do not expand docs * add swagger ui json tree formatter * add all relations from Device table * add port relations * add nodes retrieve on device or vlan * rename to GetAPIKey * update config for previous commit
This commit is contained in:
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'apchanneldist',
|
||||
label => 'Access Point Channel Distribution',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -28,13 +29,11 @@ get '/ajax/content/report/apchanneldist' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/apchanneldist.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/apchanneldist.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/apchanneldist_csv.tt', { results => \@results },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/apchanneldist_csv.tt', { results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'apclients',
|
||||
label => 'Access Point Client Count',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -37,14 +38,12 @@ get '/ajax/content/report/apclients' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/apclients.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/apclients.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/apclients_csv.tt',
|
||||
{ results => \@results },
|
||||
{ layout => undef };
|
||||
{ results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ register_report(
|
||||
tag => 'apradiochannelpower',
|
||||
label => 'Access Point Radios Channel and Power',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -38,8 +39,7 @@ get '/ajax/content/report/apradiochannelpower/data' => require_login sub {
|
||||
get '/ajax/content/report/apradiochannelpower' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
template 'ajax/report/apradiochannelpower.tt', {},
|
||||
{ layout => undef };
|
||||
template 'ajax/report/apradiochannelpower.tt';
|
||||
}
|
||||
else {
|
||||
my @results
|
||||
@@ -50,8 +50,7 @@ get '/ajax/content/report/apradiochannelpower' => require_login sub {
|
||||
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/apradiochannelpower_csv.tt',
|
||||
{ results => \@results, },
|
||||
{ layout => undef };
|
||||
{ results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'deviceaddrnodns',
|
||||
label => 'Addresses without DNS Entries',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -28,14 +29,12 @@ get '/ajax/content/report/deviceaddrnodns' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json (\@results);
|
||||
template 'ajax/report/deviceaddrnodns.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/deviceaddrnodns.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/deviceaddrnodns_csv.tt',
|
||||
{ results => \@results, },
|
||||
{ layout => undef };
|
||||
{ results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'devicebylocation',
|
||||
label => 'By Location',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -24,14 +25,12 @@ get '/ajax/content/report/devicebylocation' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/devicebylocation.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/devicebylocation.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/devicebylocation_csv.tt',
|
||||
{ results => \@results },
|
||||
{ layout => undef };
|
||||
{ results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'devicednsmismatch',
|
||||
label => 'Device Name / DNS Mismatches',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -27,14 +28,12 @@ get '/ajax/content/report/devicednsmismatch' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/devicednsmismatch.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/devicednsmismatch.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/devicednsmismatch_csv.tt',
|
||||
{ results => \@results },
|
||||
{ layout => undef };
|
||||
{ results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ register_report(
|
||||
tag => 'devicepoestatus',
|
||||
label => 'Power over Ethernet (PoE) Status',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -39,7 +40,7 @@ get '/ajax/content/report/devicepoestatus/data' => require_login sub {
|
||||
get '/ajax/content/report/devicepoestatus' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
template 'ajax/report/devicepoestatus.tt', {}, { layout => undef };
|
||||
template 'ajax/report/devicepoestatus.tt';
|
||||
}
|
||||
else {
|
||||
my @results
|
||||
@@ -50,8 +51,7 @@ get '/ajax/content/report/devicepoestatus' => require_login sub {
|
||||
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/devicepoestatus_csv.tt',
|
||||
{ results => \@results, },
|
||||
{ layout => undef };
|
||||
{ results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'duplexmismatch',
|
||||
label => 'Duplex Mismatches Between Devices',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -22,14 +23,12 @@ get '/ajax/content/report/duplexmismatch' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/duplexmismatch.tt', { results => $json, },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/duplexmismatch.tt', { results => $json, };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/duplexmismatch_csv.tt',
|
||||
{ results => \@results, },
|
||||
{ layout => undef };
|
||||
{ results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ register_report(
|
||||
tag => 'halfduplex',
|
||||
label => 'Ports in Half Duplex Mode',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
get '/ajax/content/report/halfduplex' => require_login sub {
|
||||
my $format = param('format');
|
||||
my @results
|
||||
= schema('netdisco')->resultset('DevicePort')
|
||||
->columns( [qw/ ip port name duplex /] )->search(
|
||||
@@ -30,14 +30,12 @@ get '/ajax/content/report/halfduplex' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/halfduplex.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/halfduplex.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/halfduplex_csv.tt',
|
||||
{ results => \@results },
|
||||
{ layout => undef };
|
||||
{ results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,12 +6,39 @@ use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
use NetAddr::IP::Lite ':lower';
|
||||
use POSIX qw/strftime/;
|
||||
|
||||
register_report(
|
||||
{ category => 'IP',
|
||||
tag => 'ipinventory',
|
||||
label => 'IP Inventory',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
subnet => {
|
||||
description => 'IP Prefix to search',
|
||||
required => 1,
|
||||
},
|
||||
daterange => {
|
||||
description => 'Date range to search',
|
||||
default => ('1970-01-01 to '. strftime('%Y-%m-%d', gmtime)),
|
||||
},
|
||||
age_invert => {
|
||||
description => 'Results should NOT be within daterange',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
limit => {
|
||||
description => 'Maximum number of historical records',
|
||||
enum => [qw/32 64 128 256 512 1024 2048 4096 8192/],
|
||||
default => '256',
|
||||
},
|
||||
never => {
|
||||
description => 'Include in the report IPs never seen',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -25,7 +52,10 @@ get '/ajax/content/report/ipinventory' => require_login sub {
|
||||
if (! $subnet) or ($subnet->addr eq '0.0.0.0');
|
||||
|
||||
my $agenot = param('age_invert') || '0';
|
||||
my ( $start, $end ) = param('daterange') =~ /(\d+-\d+-\d+)/gmx;
|
||||
|
||||
my $daterange = param('daterange')
|
||||
|| ('1970-01-01 to '. strftime('%Y-%m-%d', gmtime));
|
||||
my ( $start, $end ) = $daterange =~ /(\d+-\d+-\d+)/gmx;
|
||||
|
||||
my $limit = param('limit') || 256;
|
||||
my $never = param('never') || '0';
|
||||
@@ -155,13 +185,11 @@ get '/ajax/content/report/ipinventory' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/ipinventory.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/ipinventory.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/ipinventory_csv.tt', { results => \@results, },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/ipinventory_csv.tt', { results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'nodemultiips',
|
||||
label => 'Nodes with multiple active IP addresses',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -37,14 +38,12 @@ get '/ajax/content/report/nodemultiips' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/nodemultiips.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/nodemultiips.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/nodemultiips_csv.tt',
|
||||
{ results => \@results },
|
||||
{ layout => undef };
|
||||
{ results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,30 @@ register_report(
|
||||
tag => 'nodesdiscovered',
|
||||
label => 'Nodes discovered through LLDP/CDP',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
remote_id => {
|
||||
description => 'Host Name reported',
|
||||
},
|
||||
remote_type => {
|
||||
description => 'Platform reported',
|
||||
},
|
||||
aps => {
|
||||
description => 'Include Wireless APs in the report',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
phones => {
|
||||
description => 'Include IP Phones in the report',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
matchall => {
|
||||
description => 'Match all parameters (true) or any (false)',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -40,14 +64,12 @@ get '/ajax/content/report/nodesdiscovered' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/nodesdiscovered.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/nodesdiscovered.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/nodesdiscovered_csv.tt',
|
||||
{ results => \@results },
|
||||
{ layout => undef };
|
||||
{ results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'portadmindown',
|
||||
label => 'Ports administratively disabled',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -31,14 +32,12 @@ get '/ajax/content/report/portadmindown' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json (\@results);
|
||||
template 'ajax/report/portadmindown.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portadmindown.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/portadmindown_csv.tt',
|
||||
{ results => \@results, },
|
||||
{ layout => undef };
|
||||
{ results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'portblocking',
|
||||
label => 'Ports that are blocking',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -31,14 +32,12 @@ get '/ajax/content/report/portblocking' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json (\@results);
|
||||
template 'ajax/report/portblocking.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portblocking.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/portblocking_csv.tt',
|
||||
{ results => \@results, },
|
||||
{ layout => undef };
|
||||
{ results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,13 @@ register_report(
|
||||
tag => 'portmultinodes',
|
||||
label => 'Ports with multiple nodes attached',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
vlan => {
|
||||
description => 'Filter by VLAN',
|
||||
type => 'integer',
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -39,14 +46,12 @@ get '/ajax/content/report/portmultinodes' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json (\@results);
|
||||
template 'ajax/report/portmultinodes.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portmultinodes.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/portmultinodes_csv.tt',
|
||||
{ results => \@results, },
|
||||
{ layout => undef };
|
||||
{ results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,12 @@ register_report(
|
||||
tag => 'portssid',
|
||||
label => 'Port SSID Inventory',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
ssid => {
|
||||
description => 'Get details for this SSID',
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -65,14 +71,12 @@ get '/ajax/content/report/portssid' => require_login sub {
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/portssid.tt',
|
||||
{ results => $json, opt => $ssid },
|
||||
{ layout => undef };
|
||||
{ results => $json, opt => $ssid };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/portssid_csv.tt',
|
||||
{ results => \@results, opt => $ssid },
|
||||
{ layout => undef };
|
||||
{ results => \@results, opt => $ssid };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,19 @@ register_report(
|
||||
tag => 'portutilization',
|
||||
label => 'Port Utilization',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
age_num => {
|
||||
description => 'Mark as Free if down for (quantity)',
|
||||
enum => [1 .. 31],
|
||||
default => '3',
|
||||
},
|
||||
age_unit => {
|
||||
description => 'Mark as Free if down for (period)',
|
||||
enum => [qw/days weeks months years/],
|
||||
default => 'months',
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -24,13 +37,11 @@ get '/ajax/content/report/portutilization' => require_login sub {
|
||||
|
||||
if (request->is_ajax) {
|
||||
my $json = to_json (\@results);
|
||||
template 'ajax/report/portutilization.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portutilization.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/portutilization_csv.tt', { results => \@results, },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portutilization_csv.tt', { results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'portvlanmismatch',
|
||||
label => 'Port VLAN Mismatches',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -20,13 +21,11 @@ get '/ajax/content/report/portvlanmismatch' => require_login sub {
|
||||
|
||||
if (request->is_ajax) {
|
||||
my $json = to_json (\@results);
|
||||
template 'ajax/report/portvlanmismatch.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portvlanmismatch.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/portvlanmismatch_csv.tt', { results => \@results, },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portvlanmismatch_csv.tt', { results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'ssidinventory',
|
||||
label => 'SSID Inventory',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -22,13 +23,11 @@ get '/ajax/content/report/ssidinventory' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/report/portssid.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portssid.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/portssid_csv.tt', { results => \@results },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/portssid_csv.tt', { results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,19 +5,38 @@ use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
use POSIX qw/strftime/;
|
||||
|
||||
register_report({
|
||||
category => 'IP',
|
||||
tag => 'subnets',
|
||||
label => 'Subnet Utilization',
|
||||
provides_csv => 1,
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
subnet => {
|
||||
description => 'IP Prefix to search',
|
||||
default => '0.0.0.0/32',
|
||||
},
|
||||
daterange => {
|
||||
description => 'Date range to search',
|
||||
default => ('1970-01-01 to '. strftime('%Y-%m-%d', gmtime)),
|
||||
},
|
||||
age_invert => {
|
||||
description => 'Results should NOT be within daterange',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
get '/ajax/content/report/subnets' => require_login sub {
|
||||
my $subnet = param('subnet') || '0.0.0.0/32';
|
||||
my $agenot = param('age_invert') || '0';
|
||||
my ( $start, $end ) = param('daterange') =~ /(\d+-\d+-\d+)/gmx;
|
||||
|
||||
my $daterange = param('daterange')
|
||||
|| ('1970-01-01 to '. strftime('%Y-%m-%d', gmtime));
|
||||
my ( $start, $end ) = $daterange =~ /(\d+-\d+-\d+)/gmx;
|
||||
$start = $start . ' 00:00:00';
|
||||
$end = $end . ' 23:59:59';
|
||||
|
||||
@@ -29,13 +48,11 @@ get '/ajax/content/report/subnets' => require_login sub {
|
||||
return unless scalar @results;
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
template 'ajax/report/subnets.tt', { results => \@results },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/subnets.tt', { results => \@results };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/subnets_csv.tt', { results => \@results },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/subnets_csv.tt', { results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ register_report(
|
||||
tag => 'vlaninventory',
|
||||
label => 'VLAN Inventory',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -36,13 +37,11 @@ get '/ajax/content/report/vlaninventory' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json (\@results);
|
||||
template 'ajax/report/vlaninventory.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/vlaninventory.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/report/vlaninventory_csv.tt', { results => \@results },
|
||||
{ layout => undef };
|
||||
template 'ajax/report/vlaninventory_csv.tt', { results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user