add csv download to duplex mismatch, half duplex, and port utilization reports

This commit is contained in:
Eric A. Miller
2013-09-19 22:30:27 -04:00
parent 5d4df72a24
commit d3553d2623
9 changed files with 113 additions and 16 deletions

View File

@@ -7,20 +7,38 @@ use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_report({
category => 'Port',
tag => 'duplexmismatch',
label => 'Duplex Mismatches Between Devices',
});
register_report(
{ category => 'Port',
tag => 'duplexmismatch',
label => 'Duplex Mismatches Between Devices',
}
);
ajax '/ajax/content/report/duplexmismatch' => require_login sub {
my $set = schema('netdisco')->resultset('Virtual::DuplexMismatch');
return unless $set->count;
content_type('text/html');
template 'ajax/report/duplexmismatch.tt', {
results => $set,
}, { layout => undef };
template 'ajax/report/duplexmismatch.tt', { results => $set, },
{ layout => undef };
};
get '/ajax/content/report/duplexmismatch' => require_login sub {
my $format = param('format');
my $set = schema('netdisco')->resultset('Virtual::DuplexMismatch');
return unless $set->count;
if ( $format eq 'csv' ) {
header( 'Content-Type' => 'text/comma-separated-values' );
header( 'Content-Disposition' =>
"attachment; filename=\"duplexmismatch.csv\"" );
template 'ajax/report/duplexmismatch_csv.tt', { results => $set, },
{ layout => undef };
}
else {
return;
}
};
true;

View File

@@ -26,4 +26,25 @@ ajax '/ajax/content/report/halfduplex' => require_login sub {
}, { layout => undef };
};
get '/ajax/content/report/halfduplex' => require_login sub {
my $format = param('format');
my $set = schema('netdisco')->resultset('DevicePort')->search(
{ up => 'up', duplex => { '-ilike' => 'half' } },
{ order_by => [qw/device.dns port/], prefetch => 'device' },
);
return unless $set->count;
if ( $format eq 'csv' ) {
header( 'Content-Type' => 'text/comma-separated-values' );
header( 'Content-Disposition' =>
"attachment; filename=\"halfduplex.csv\"" );
template 'ajax/report/halfduplex_csv.tt', { results => $set, },
{ layout => undef };
}
else {
return;
}
};
true;

View File

@@ -7,20 +7,38 @@ use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_report({
category => 'Device',
tag => 'portutilization',
label => 'Port Utilization',
});
register_report(
{ category => 'Device',
tag => 'portutilization',
label => 'Port Utilization',
}
);
ajax '/ajax/content/report/portutilization' => require_login sub {
return unless schema('netdisco')->resultset('Device')->count;
my $set = schema('netdisco')->resultset('Virtual::PortUtilization');
content_type('text/html');
template 'ajax/report/portutilization.tt', {
results => $set,
}, { layout => undef };
template 'ajax/report/portutilization.tt', { results => $set, },
{ layout => undef };
};
get '/ajax/content/report/portutilization' => require_login sub {
my $format = param('format');
return unless schema('netdisco')->resultset('Device')->count;
my $set = schema('netdisco')->resultset('Virtual::PortUtilization');
if ( $format eq 'csv' ) {
header( 'Content-Type' => 'text/comma-separated-values' );
header( 'Content-Disposition' =>
"attachment; filename=\"portutilization.csv\"" );
template 'ajax/report/portutilization_csv.tt', { results => $set, },
{ layout => undef };
}
else {
return;
}
};
true;