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:
@@ -29,7 +29,7 @@ get '/inventory' => require_login sub {
|
||||
template 'inventory', {
|
||||
platforms => [ $platforms->hri->all ],
|
||||
releases => [ @release_list ],
|
||||
};
|
||||
}, { layout => 'main' };
|
||||
};
|
||||
|
||||
true;
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,8 +8,52 @@ use List::MoreUtils ();
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
|
||||
register_search_tab(
|
||||
{ tag => 'device', label => 'Device', provides_csv => 1 } );
|
||||
register_search_tab({
|
||||
tag => 'device',
|
||||
label => 'Device',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
q => {
|
||||
description => 'Partial match of Device contact, serial, module serials, location, name, description, dns, or any IP alias',
|
||||
},
|
||||
name => {
|
||||
description => 'Partial match of the Device name',
|
||||
},
|
||||
location => {
|
||||
description => 'Partial match of the Device location',
|
||||
},
|
||||
dns => {
|
||||
description => 'Partial match of any of the Device IP aliases',
|
||||
},
|
||||
ip => {
|
||||
description => 'IP or IP Prefix within which the Device must have an interface address',
|
||||
},
|
||||
description => {
|
||||
description => 'Partial match of the Device description',
|
||||
},
|
||||
model => {
|
||||
description => 'Exact match of the Device model',
|
||||
},
|
||||
os => {
|
||||
description => 'Exact match of the Device operating system',
|
||||
},
|
||||
os_ver => {
|
||||
description => 'Exact match of the Device operating system version',
|
||||
},
|
||||
vendor => {
|
||||
description => 'Exact match of the Device vendor',
|
||||
},
|
||||
layers => {
|
||||
description => 'OSI Layer which the device must support',
|
||||
},
|
||||
matchall => {
|
||||
description => 'If true, all fields (except "q") must match the Device',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
# device with various properties or a default match-all
|
||||
get '/ajax/content/search/device' => require_login sub {
|
||||
@@ -40,13 +84,11 @@ get '/ajax/content/search/device' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/search/device.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/search/device.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/search/device_csv.tt', { results => \@results, },
|
||||
{ layout => undef };
|
||||
template 'ajax/search/device_csv.tt', { results => \@results, };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,51 @@ use NetAddr::MAC ();
|
||||
use App::Netdisco::Web::Plugin;
|
||||
use App::Netdisco::Util::Web 'sql_match';
|
||||
|
||||
register_search_tab({ tag => 'node', label => 'Node' });
|
||||
register_search_tab({
|
||||
tag => 'node',
|
||||
label => 'Node',
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
q => {
|
||||
description => 'MAC Address or IP Address or Hostname (without Domain Suffix) of a Node (supports SQL or "*" wildcards)',
|
||||
required => 1,
|
||||
},
|
||||
partial => {
|
||||
description => 'Partially match the "q" parameter (wildcard characters not required)',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
deviceports => {
|
||||
description => 'MAC Address search will include Device Port MACs',
|
||||
type => 'boolean',
|
||||
default => 'true',
|
||||
},
|
||||
show_vendor => {
|
||||
description => 'Include interface Vendor in results',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
archived => {
|
||||
description => 'Include archived records in results',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
daterange => {
|
||||
description => 'Date Range in format "YYYY-MM-DD to YYYY-MM-DD"',
|
||||
},
|
||||
age_invert => {
|
||||
description => 'Date Range is NOT within the supplied range',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
# mac_format is used only in the template (will be IEEE) in results
|
||||
#mac_format => {
|
||||
#},
|
||||
# stamps param is used only in the template (they will be included)
|
||||
#stamps => {
|
||||
#},
|
||||
],
|
||||
});
|
||||
|
||||
# nodes matching the param as an IP or DNS hostname or MAC
|
||||
ajax '/ajax/content/search/node' => require_login sub {
|
||||
@@ -144,7 +188,7 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
ports => $ports,
|
||||
wireless => $wireless,
|
||||
netbios => $netbios,
|
||||
}, { layout => undef };
|
||||
};
|
||||
}
|
||||
else {
|
||||
my $ports = param('deviceports')
|
||||
@@ -157,7 +201,7 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
ports => $ports,
|
||||
wireless => $wireless,
|
||||
netbios => $netbios,
|
||||
}, { layout => undef };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +244,7 @@ ajax '/ajax/content/search/node' => require_login sub {
|
||||
template 'ajax/search/node_by_ip.tt', {
|
||||
macs => $set,
|
||||
archive_filter => {@active},
|
||||
}, { layout => undef };
|
||||
};
|
||||
};
|
||||
|
||||
true;
|
||||
|
||||
@@ -7,7 +7,33 @@ use Dancer::Plugin::Auth::Extensible;
|
||||
use App::Netdisco::Web::Plugin;
|
||||
use App::Netdisco::Util::Web 'sql_match';
|
||||
|
||||
register_search_tab( { tag => 'port', label => 'Port', provides_csv => 1 } );
|
||||
register_search_tab({
|
||||
tag => 'port',
|
||||
label => 'Port',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
q => {
|
||||
description => 'Port name or VLAN or MAC address',
|
||||
required => 1,
|
||||
},
|
||||
partial => {
|
||||
description => 'Search for a partial match on parameter "q"',
|
||||
type => 'boolean',
|
||||
default => 'true',
|
||||
},
|
||||
uplink => {
|
||||
description => 'Include uplinks in results',
|
||||
type => 'boolean',
|
||||
default => 'false',
|
||||
},
|
||||
ethernet => {
|
||||
description => 'Only Ethernet type interfaces in results',
|
||||
type => 'boolean',
|
||||
default => 'true',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
# device ports with a description (er, name) matching
|
||||
get '/ajax/content/search/port' => require_login sub {
|
||||
@@ -67,13 +93,11 @@ get '/ajax/content/search/port' => require_login sub {
|
||||
|
||||
if ( request->is_ajax ) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/search/port.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/search/port.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/search/port_csv.tt', { results => \@results },
|
||||
{ layout => undef };
|
||||
template 'ajax/search/port_csv.tt', { results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,18 @@ use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Web::Plugin;
|
||||
|
||||
register_search_tab( { tag => 'vlan', label => 'VLAN', provides_csv => 1 } );
|
||||
register_search_tab({
|
||||
tag => 'vlan',
|
||||
label => 'VLAN',
|
||||
provides_csv => 1,
|
||||
api_endpoint => 1,
|
||||
api_parameters => [
|
||||
q => {
|
||||
description => 'VLAN name or number',
|
||||
required => 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
# devices carrying vlan xxx
|
||||
get '/ajax/content/search/vlan' => require_login sub {
|
||||
@@ -28,13 +39,11 @@ get '/ajax/content/search/vlan' => require_login sub {
|
||||
|
||||
if (request->is_ajax) {
|
||||
my $json = to_json( \@results );
|
||||
template 'ajax/search/vlan.tt', { results => $json },
|
||||
{ layout => undef };
|
||||
template 'ajax/search/vlan.tt', { results => $json };
|
||||
}
|
||||
else {
|
||||
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||
template 'ajax/search/vlan_csv.tt', { results => \@results },
|
||||
{ layout => undef };
|
||||
template 'ajax/search/vlan_csv.tt', { results => \@results };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user