J'e
J'e

Reputation: 3726

Generate a html report from Trivy

I'm trying to generate a HTML report from Trivy. On the example page, they provide trivy image --format template --template "@contrib/html.tpl" -o report.html golang:1.12-alpine. When I run this, I get the following error,

FATAL report error: unable to write results: failed to initialize template writer: error retrieving template from path: open contrib/html.tpl: no such file or directory

Based on the documentation, It looks like this is a default template so I'm assuming it's included. My logic here is that there is no "/" following the "@" in the template path.

I'm currently on version 0.41.0

Upvotes: 5

Views: 14221

Answers (5)

nealray
nealray

Reputation: 31

One thing you should understand here. Downloading template from this url https://github.com/aquasecurity/trivy/blob/main/contrib/html.tpl downloads all html page elements present in this page.

So in order to download only template file , you have to download its raw content. To get the raw content , click on Raw button provided on the upper right side of the page. Which takes you here https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/html.tpl.

Here are the steps I have executed in ubuntu to generate HTML report in CI pipeline:

wget https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/html.tpl
sudo cp html.tpl /usr/bin/html.tpl
trivy image --format template --template "@/usr/bin/html.tpl" -o report.html {image}

Upvotes: 3

rgshenoy
rgshenoy

Reputation: 449

I did not install trivy from RPM and had no files other than a solid trivy binary of a few 10 MBs. Downloaded the html.tpl template from their github repo https://github.com/aquasecurity/trivy/blob/main/contrib/html.tpl and placed it in /usr/bin/html.tpl and used the command line: trivy image --format template --template "@/usr/bin/html.tpl" -o report.html image-name

Upvotes: 5

Krishna Mohan
Krishna Mohan

Reputation: 31

First, we should find the file in your system "html.tpl". I am using a mac and when I ran the below find command

find / -name html.tpl

output: /System/Volumes/Data/Applications/...../.trivy/contrib/html.tpl

I passed the html.tpl path in the command

trivy image --format template --template html path -o report.html image name

It worked.

Upvotes: 0

Karlito Brigante
Karlito Brigante

Reputation: 58

According to the documentation for 0.41 you need to find out the path where the templates are saved on your system. I also use the standard template and need to set "@/usr/local/share/trivy/templates/html.tpl" as path. I guess it depends on your operating system and the way you've installed trivy. I run it on a centOS 7 System

Information from the Documentation: enter image description here

Example command from documentation: $ trivy image --format template --template "@/path/to/template" golang:1.12-alpine -o your_output.html

Upvotes: 2

LurkyMcLurkBurger
LurkyMcLurkBurger

Reputation: 11

Not sure what operating system you're using, but on Kali Linux I do the following:

trivy fs FOLDER_PATH --format -template --template 
      "@/usr/share/trivy/templates/html.tpl" --output NAME_OF_FOLDER.html

I like customizing the .tpl file to generate a html page to my liking, so I generally copy the file somewhere else and edit it.

--template "@/home/user/Desktop/html.tpl" (or wherever you wanna put it)

The example you link is from old documentation. Here's something newer that might help: https://aquasecurity.github.io/trivy/v0.41/docs/configuration/reporting/#default-templates

Upvotes: 1

Related Questions