"""Print a compact inventory from raw Trivy JSON.""" import collections import json import sys from pathlib import Path for path in sorted(Path(sys.argv[1]).glob("*.json")): report = json.loads(path.read_text()) matches = {} for target in report.get("Results", []): for entry in target.get("Vulnerabilities") or []: key = entry["VulnerabilityID"], entry["PkgName"], entry["InstalledVersion"] matches[key] = entry counts = collections.Counter(entry["Severity"] for entry in matches.values()) print(path.name, dict(sorted(counts.items())))