To convert a Trivy JSON report into an HTML format, you have two primary approaches: using Trivy's built-in template functionality or employing external tools designed for this purpose.
1. Using Trivy's Built-in HTML Template:
Trivy provides a default HTML template that can be utilized to generate HTML reports directly from your scans. Here's how you can do it:
- Download the HTML Template:
First, obtain the
html.tpl template from Trivy's GitHub repository. Ensure you download the raw content to avoid any formatting issues. You can do this by clicking on the "Raw" button on the template's GitHub page or using the following command:
wget https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/html.tpl -O html.tpl
- Run Trivy with the HTML Template:
Execute Trivy with the
--format template option, specifying the path to the downloaded html.tpl file. Ensure you prefix the template path with an @ symbol:
trivy image --format template --template "@./html.tpl" -o report.html your_image_name
Replace your_image_name with the name of the image you are scanning. This command will generate an report.html file containing the scan results in HTML format.
2. Using External Tools:
Alternatively, you can use external tools designed to convert Trivy JSON reports into HTML. One such tool is trivy-html-report, a CLI utility that facilitates this conversion.
- Install
trivy-html-report:
Ensure you have Python 3.8 or higher installed. You can install the tool using pip:
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ trivy-html-report-andresdev4
- Convert the JSON Report to HTML:
After generating a Trivy JSON report, use the following command to convert it to HTML:
trivy-to-html --project-name "Your Project Name" \
--scan-author "Author Name" \
--project-url "https://your.project.url" \
--input-json "./report.json" \
--output-html "./report.html" \
--report-title "Your Report Title"
Replace the placeholders with your project's details. This command will produce an report.html file with a detailed and visually appealing representation of your scan results.
For more information on trivy-html-report, refer to its GitHub repository: (github.com)
By following either of these methods, you can effectively convert Trivy JSON reports into HTML format for easier analysis and sharing.