Skip to content

Commit

Permalink
Add html output template
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed Jan 12, 2020
1 parent 35dc0b0 commit c00afe6
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 6 deletions.
6 changes: 5 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
* [X] Deprecate Report->AnalysisResult in favor of using Renderer directly
* [X] Commands should allow for arbitrary links for further information or actions
* [X] Command result should store command execution time
* [ ] Rendering should allow for HTML
* [X] Rendering should allow for HTML
* [X] Include failures in report
* [X] Allow for generic handlebar based rendering via CLI
* [ ] Templates
* [ ] Add Profile name
* [ ] crate info: Version
* [ ] Show progressbar by default if terminal
* [ ] Create linux and macos configuration
* macOS
* sw_vers
Expand Down
150 changes: 150 additions & 0 deletions contrib/html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<title>Use Report - {{hostname}} on {{rfc2822 date_time}}</title>
</head>
<body>
<div class="container-fluid">
<h1>Use Report - {{hostname}} on {{rfc2822 date_time}}</h1>
<p>
Date: <code>{{rfc2822 date_time}}</code><br/>
Hostname: <code>{{hostname}}</code><br/>
Host OS: <code>{{uname}}</code>
</p>
<h2>Run Configuration</h2>
<p>
Repetitions: {{repetitions}}<br/>
Parallelism: {{max_parallel_commands}}<br/>
Profile: {{profile_name}}
</p>

<div>
<h2>Host Information</h2>
{{#each hostinfo_results as |result|}}
{{~#if result.Success}}
{{~#with result.Success}}
<h3 class="text-success">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}</h3>
<div class="border border-secondary rounded"><pre>{{this.stdout}}</pre></div>
<p>
<small>
{{~#with this.command}}
{{#if this.description}}<p>{{this.description}}</p>{{/if}}
Command: <code>{{this.command}}</code> [{{../run_time_ms}} ms]<br/>
{{#each this.links as |link|}}[<a href="{{link.url}}">{{link.name}}</a>] {{/each}}
{{~/with}}
</small>
</p>
{{/with}}
{{~/if}}

{{~#if result.Failed}}
{{~#with result.Failed}}
<h3 class="text-warning">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}:
Failed</h3>
<p>
<small>
Command: <code>{{this.command.command}}</code> [{{this.run_time_ms}} ms]<br/>
</small>
</p>
{{/with}}
{{~/if}}

{{~#if result.Timeout}}
{{~#with result.Timeout}}
<h3 class="text-warning">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}: Timed
out</h3>
<p>
<small>
Command: <code>{{this.command.command}}</code> [{{this.run_time_ms}} ms]<br/>
</small>
</p>
{{/with}}
{{~/if}}

{{~#if result.Error}}
{{~#with result.Error}}
<h3 class="text-danger">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}: Error</h3>
<p>
Reason: {{this.reason}}<br/>
<small>
Command: <code>{{this.command.command}}</code> [{{this.run_time_ms}} ms]<br/>
</small>
</p>
{{/with}}
{{~/if}}

{{~/each}}
</div>

<hr/>

{{#each command_results as |run|}}
<h2>Command Results - Run {{inc @index}}</h2>
{{#each run as |result|}}
{{~#if result.Success}}
{{~#with result.Success}}
<h3 class="text-success">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}</h3>
<div class="border border-secondary rounded"><pre>{{this.stdout}}</pre></div>
<p>
<small>
{{~#with this.command}}
{{#if this.description}}<p>{{this.description}}</p>{{/if}}
Command: <code>{{this.command}}</code> [{{../run_time_ms}} ms]<br/>
{{#each this.links as |link|}}[<a href="{{link.url}}">{{link.name}}</a>] {{/each}}
{{~/with}}
</small>
</p>
{{/with}}
{{~/if}}

{{~#if result.Failed}}
{{~#with result.Failed}}
<h3 class="text-warning">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}:
Failed</h3>
<p>
<small>
Command: <code>{{this.command.command}}</code> [{{this.run_time_ms}} ms]<br/>
</small>
</p>
{{/with}}
{{~/if}}

{{~#if result.Timeout}}
{{~#with result.Timeout}}
<h3 class="text-warning">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}: Timed
out</h3>
<p>
<small>
Command: <code>{{this.command.command}}</code> [{{this.run_time_ms}} ms]<br/>
</small>
</p>
{{/with}}
{{~/if}}

{{~#if result.Error}}
{{~#with result.Error}}
<h3 class="text-danger">{{#if this.command.title}}{{this.command.title}}{{else}}{{this.command.name}}{{/if}}: Error</h3>
<p>
Reason: {{this.reason}}<br/>
<small>
Command: <code>{{this.command.command}}</code> [{{this.run_time_ms}} ms]<br/>
</small>
</p>
{{/with}}
{{~/if}}

{{~/each}}

{{/each}}

<hr/>

<small>Please see <a href="https://medium.com/netflix-techblog/linux-performance-analysis-in-60-000-milliseconds-accc10403c55">Linux Performance Analysis in 60,000 Milliseconds</a> for details about the individual reports.</small>
</div>
</body>
</html>
12 changes: 8 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Opt {
#[structopt(short, long, parse(from_os_str))]
config: Option<PathBuf>,
/// Output format
#[structopt(short, long, possible_values = & ["hbs", "json", "markdown"], default_value = "markdown")]
#[structopt(short, long, possible_values = & ["hbs", "html", "json", "markdown"], default_value = "markdown")]
output_type: OutputType,
/// Set output template if output-type is set to "hbs"
#[structopt(long)]
Expand Down Expand Up @@ -64,7 +64,8 @@ impl Opt {
#[derive(Debug, PartialEq, Eq)]
pub enum OutputType {
Hbs,
JSON,
Html,
Json,
Markdown,
}

Expand All @@ -74,7 +75,8 @@ impl FromStr for OutputType {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_ref() {
"hbs" => Ok(OutputType::Hbs),
"json" => Ok(OutputType::JSON),
"html" => Ok(OutputType::Html),
"json" => Ok(OutputType::Json),
"markdown" => Ok(OutputType::Markdown),
_ => Err(format_err!("failed to parse {} as output type", s)),
}
Expand Down Expand Up @@ -189,8 +191,9 @@ fn create_renderer<W: Write>(
let renderer = renderer::HbsRenderer::from_file(template_file)?;
Box::new(renderer)
}
OutputType::Html => Box::new(renderer::HbsRenderer::new(defaults::HTML_TEMPLATE)),
OutputType::Json => Box::new(renderer::JsonRenderer::new()),
OutputType::Markdown => Box::new(renderer::HbsRenderer::new(defaults::MD_TEMPLATE)),
OutputType::JSON => Box::new(renderer::JsonRenderer::new()),
};

Ok(renderer)
Expand Down Expand Up @@ -226,6 +229,7 @@ fn create_progress_bar(expected: usize) -> Sender<usize> {
#[cfg(target_os = "macos")]
mod defaults {
pub(crate) static CONFIG: &str = include_str!("../../contrib/osx.conf");
pub(crate) static HTML_TEMPLATE: &str = include_str!("../../contrib/html.hbs");
pub(crate) static MD_TEMPLATE: &str = include_str!("../../contrib/markdown.hbs");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/osx_unsuccessful.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ name = "vm_stat"
title = "Virtual Memory statistics"
description = "Current memory usage and statistics in pages"
command = "vm_stat -c 6 1"
timeout = 5
timeout = 1
links = [
{ name = "man", url = "https://www.unix.com/man-page/osx/1m/vmstat/" },
]
Expand Down

0 comments on commit c00afe6

Please sign in to comment.