Files
felhom.eu/documentation/audits/burndown2-2026-10-16/tools/trivy_counts.py
T

23 lines
1.0 KiB
Python

#!/usr/bin/env python3
"""trivy_counts.py <trivy.json>... — per image and per target: CRITICAL/HIGH counts, all and fixable (a fixed version
exists). The burndown-2 before/after table (R-972)."""
import json, sys
from collections import Counter
for p in sys.argv[1:]:
d = json.load(open(p))
print("== %s" % d.get("ArtifactName"))
tot_all, tot_fix = Counter(), Counter()
for r in d.get("Results", []) or []:
a, f = Counter(), Counter()
for v in r.get("Vulnerabilities") or []:
sev = v.get("Severity")
a[sev] += 1
if v.get("FixedVersion"):
f[sev] += 1
tot_all += a; tot_fix += f
if a:
print(" %-60s %-9s crit %3d (fixable %3d) high %3d (fixable %3d)" % (r.get("Target", "")[:60], r.get("Type", ""),
a["CRITICAL"], f["CRITICAL"], a["HIGH"], f["HIGH"]))
print(" %-60s %-9s crit %3d (fixable %3d) high %3d (fixable %3d)" % ("TOTAL", "", tot_all["CRITICAL"], tot_fix["CRITICAL"],
tot_all["HIGH"], tot_fix["HIGH"]))