add csv download to duplex mismatch, half duplex, and port utilization reports
This commit is contained in:
		| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| [% INCLUDE "download_as.tt" %] | ||||
| <table class="table table-bordered table-condensed table-striped nd_floatinghead"> | ||||
|   <thead> | ||||
|     <tr> | ||||
|   | ||||
							
								
								
									
										13
									
								
								Netdisco/share/views/ajax/report/duplexmismatch_csv.tt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Netdisco/share/views/ajax/report/duplexmismatch_csv.tt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| [% USE CSV -%] | ||||
| [% CSV.dump([ 'Left Device' 'Port' 'Duplex' 'Right Device' 'Port' 'Duplex' ]) %] | ||||
|  | ||||
| [% WHILE (row = results.next) %] | ||||
|   [% mylist = [] %] | ||||
|   [% device_left = row.left_dns || row.left_ip %] | ||||
|   [% device_right = row.right_dns || row.right_ip %] | ||||
|   [% FOREACH col IN [ device_left row.left_port row.left_duplex.ucfirst device_right row.right_port row.right_duplex.ucfirst ] %] | ||||
|     [% mylist.push(col) %] | ||||
|   [% END %] | ||||
|   [% CSV.dump(mylist) %] | ||||
|  | ||||
| [% END %] | ||||
| @@ -1,3 +1,4 @@ | ||||
| [% INCLUDE "download_as.tt" %] | ||||
| <table class="table table-bordered table-condensed table-striped nd_floatinghead"> | ||||
|   <thead> | ||||
|     <tr> | ||||
|   | ||||
							
								
								
									
										12
									
								
								Netdisco/share/views/ajax/report/halfduplex_csv.tt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Netdisco/share/views/ajax/report/halfduplex_csv.tt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| [% USE CSV -%] | ||||
| [% CSV.dump([ 'Device' 'Port' 'Description' 'Duplex' ]) %] | ||||
|  | ||||
| [% WHILE (row = results.next) %] | ||||
|   [% mylist = [] %] | ||||
|   [% device = row.device.dns || row.device.ip %] | ||||
|   [% FOREACH col IN [ device row.port row.name row.duplex.ucfirst ] %] | ||||
|     [% mylist.push(col) %] | ||||
|   [% END %] | ||||
|   [% CSV.dump(mylist) %] | ||||
|  | ||||
| [% END %] | ||||
| @@ -1,3 +1,4 @@ | ||||
| [% INCLUDE "download_as.tt" %] | ||||
| <table class="table table-bordered table-condensed table-hover nd_floatinghead"> | ||||
|   <thead> | ||||
|     <tr> | ||||
|   | ||||
							
								
								
									
										12
									
								
								Netdisco/share/views/ajax/report/portutilization_csv.tt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Netdisco/share/views/ajax/report/portutilization_csv.tt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| [% USE CSV -%] | ||||
| [% CSV.dump([ 'Device' 'Total Ports' 'In Use' 'Shutdown' 'Free' ]) %] | ||||
|  | ||||
| [% WHILE (row = results.next) %] | ||||
|   [% mylist = [] %] | ||||
|   [% device = row.dns || row.ip %] | ||||
|   [% FOREACH col IN [ device row.port_count row.ports_in_use row.ports_shutdown row.ports_free ] %] | ||||
|     [% mylist.push(col) %] | ||||
|   [% END %] | ||||
|   [% CSV.dump(mylist) %] | ||||
|  | ||||
| [% END %] | ||||
		Reference in New Issue
	
	Block a user