-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Templates for grype output. HTML template #724
Comments
(1) ((directory with templates)): Yes, great idea ! |
Is the correct usage to redirect the output to an html file for viewing in a browser in a human readable format? It generates the html files with the output, but it is not formatted in any way. Guessing I a not doing this correctly or am missing something.
|
Sorry for asking here, but it's also template related. Is there any BTW : that would fix the |
Inspired from the html output of https://sourceforge.net/projects/command-output-to-html-table/ I created a simple html table template. Works fine for me, is human readable and interactive: <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="ISO-8859-1">
<title>Grype</title>
<script>
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who do not match the search query
for (i = 1; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td");
for (j = 0; j < td.length; j++) {
var tdata = td[j];
if (tdata) {
if (tdata.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
break;
} else {
tr[i].style.display = "none";
}
}
}
}
}
</script>
<style type="text/css">
table,
th,
td {
border: 1px solid black; // changing-colors
// word-wrap: break-word;
}
tr:first-child {
font-weight: bold;
}
tr:nth-child(even) {
background: #eef
}
// changing-colors
tr:nth-child(odd) {
background: #fee
}
// changing-colors
* {
box-sizing: border-box;
}
#myInput {
background-image: url("search.png");
background-position: left center;
background-repeat: no-repeat;
width: 94%;
font-size: 16px;
padding: 8px 20px 8px 40px;
border: 2px solid Tomato; // changing-colors
margin-bottom: 18px;
}
#myTable {
border-collapse: collapse;
border: 1px solid #ddd; // changing-colors
width: 100%;
margin-top: 18px;
// Remove the // in front of the below two lines, to get fixed-width
// table-layout: fixed;
// word-wrap: break-word;
// font-size: 18px;
}
#myTable th,
#myTable td {
text-align: left;
padding: 12px;
}
#myTable tr {
border-bottom: 1px solid #ddd; // changing-colors
}
#myTable tr:first-child:hover,
#myTable tr:hover {
background-color: rgb(4, 112, 155); // changing-colors
}
#myTable tr:first-child {
background-color: rgb(4, 112, 155); // changing-colors
font-weight: bold;
}
</style>
</head>
<body>
<h2 style="text-align:center;background-color:DodgerBlue;color:White;">Identified Vulnerabilites</h2>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search in all Fields...."
title="Type in a Search String" autofocus="autofocus">
<table id="myTable">
<tr>
<th>NAME</th>
<th>INSTALLED</th>
<th>TYPE</th>
<th>VULNERABILITY</th>
<th>SEVERITY</th>
<th>DESCRIPTION</th>
<th>STATE</th>
<th>FIXED IN</th>
</tr>
{{- range .Matches}}
<tr>
<td>"{{.Artifact.Name}}"</td>
<td>"{{.Artifact.Version}}"</td>
<td>"{{.Artifact.Type}}"</td>
<td>"{{.Vulnerability.ID}}"</td>
<td>"{{.Vulnerability.Severity}}"</td>
<td>"{{.Vulnerability.Description}}"</td>
<td>"{{.Vulnerability.Fix.State}}"</td>
<td>"{{.Vulnerability.Fix.Versions}}"</td>
</tr>
{{- end}}
</table>
</body>
</html> Copy/paste into a file like grype docker:ubuntu:focal -o template -t html.tmpl > grype.html Praise the sourceforge project for its html layout 🥇 ! |
@ida-greuelr this is awesome! |
Closing this issue with the template provided if anyone else objects or has related pr to file under issue just tag me and we can sort it |
1 similar comment
Closing this issue with the template provided if anyone else objects or has related pr to file under issue just tag me and we can sort it |
Hi, can I access the name to the input scanned object (docker image, file, directory,...) through a variable from within the template ❔ That would be very usefiul. Should I create a dedicated issue ? |
Forget my previous question cf documentation :
|
@ida-greuelr , to put the template in security and start some mode devs on templates, I created this https://dev.to/optnc/grype-0420-is-out-and-hello-grype-contribs-3g4i We'll work on imprving templates and some other stuffs. |
I'm having trouble understanding how the json names map back to the template. I was trying to extract the artifact path using .Artifact.Locations.Path, but that throws the error below ERROR unable to show grype-vulnerability-scanning-finished event: unable to show vulnerability report: unable to execute supplied template: template: html.tmpl:131:22: executing "html.tmpl" at <.Artifact.Locations.Path>: can't evaluate field Path in type []source.Coordinates |
@rtarquini
|
@mike-19 ah, I forgot about that |
I created a new fancy html template with some filtering using datatables.js. It's available as a gist here |
Wow thanks for the PR @OnceUponALoop! Let me give this a look and we'll include it under our template folder. This is excellent! |
Hi! Does someone have templates for grype? I need to scan my images to human-readable format HTML.
I think will be great if we can have a directory with templates for grype project.
The text was updated successfully, but these errors were encountered: