From 69d4e2fbea0b141c5f451a60423995ce294f40a5 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Fri, 30 Nov 2018 13:06:49 +0000 Subject: [PATCH] A bit of work on the html report template --- mysqltuner.pl | 14 ++- template_example.tpl | 250 ++++++++++++++++++------------------------- 2 files changed, 117 insertions(+), 147 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index d9a2b43..6237c2c 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -6211,26 +6211,33 @@ sub dump_result { if ( $opt{'reportfile'} ne 0 ) { eval { require Text::Template }; + eval { require JSON }; if ($@) { badprint "Text::Template Module is needed."; die "Text::Template Module is needed."; } - my $vars = { 'data' => Dumper( \%result ) }; + my $json = JSON->new->allow_nonref; + my $json_text = $json->pretty->encode( \%result ); + my %vars = ( + 'data' => \%result, + 'debug' => $json_text, + ); my $template; { no warnings 'once'; $template = Text::Template->new( TYPE => 'STRING', PREPEND => q{;}, - SOURCE => $templateModel + SOURCE => $templateModel, + DELIMITERS => [ '[%', '%]' ] ) or die "Couldn't construct template: $Text::Template::ERROR"; } open my $fh, q(>), $opt{'reportfile'} or die "Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory"; - $template->fill_in( HASH => $vars, OUTPUT => $fh ); + $template->fill_in( HASH => \%vars, OUTPUT => $fh ); close $fh; } @@ -6382,7 +6389,6 @@ You must provide the remote server's total memory when connecting to other serve --pfstat Print Performance schema --nopfstat Don't Print Performance schema --verbose Prints out all options (default: no verbose, dbstat, idxstat, sysstat, tbstat, pfstat) - --bannedports Ports banned separated by comma(,) --maxportallowed Number of ports opened allowed on this hosts --cvefile CVE File for vulnerability checks diff --git a/template_example.tpl b/template_example.tpl index b8840c2..bfb2750 100644 --- a/template_example.tpl +++ b/template_example.tpl @@ -1,153 +1,117 @@ - + - - - - - MySQL Tuner - - - - - + + + + - - - - - - - - - - - -
-
-

Home

-
Report date:
-
Report host:
-
Server version:
-
{$data}
-
-
-
-

Raw Result Data Structure

-
Report date:
-
Report host:
-
Server version:
-
{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}{$data}
-					{$data}
-				{$data}
-
-
- -
- - -
-
- MySQL Tuner 1.7.13 + /*code { + /* font-size: 80%; + /*}*/ + .code-pre { + background-color: #eee; + padding: 1rem; + font-size: 80%; + } + + MySQL Tuner + + +
+
+

MySQL Tuner

-
+ +
+
+

Home

+
Report date: [% localtime %]
+
Report host: [% $data{'Variables'}{'hostname'} %]
+
Report OS: [% $data{'OS'}{'OS Type'} %], Architecture:[% $data{'OS'}{'Architecture'} %], Ram: [% $data{'OS'}{'Physical Memory'}{'pretty'} %]
+
Server version: [% $data{'Variables'}{'version'} %], [% $data{'Variables'}{'version_compile_machine'} %], [% $data{'Status'}{'version_comment'} %]
+
+

Recommendations

+
    + [% + foreach $i ( @{$data{'Recommendations'}} ) { + $OUT .= "
  • $i
  • "; + } + %] +
+

Adjust variables

+
    + [% + foreach $i ( @{$data{'Adjust variables'}} ) { + $OUT .= "
  • $i
  • "; + } + %] +
+
+
+
+

Raw Result Data Structure

+
[% $debug %]
+
+
- - \ No newline at end of file +
+ +
+
+ MySQL Tuner 1.7.13 +
+
+ + + + + + +