-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrivy-json-to-csv.py
More file actions
33 lines (27 loc) · 1.07 KB
/
trivy-json-to-csv.py
File metadata and controls
33 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
import pandas as pd
import os
# Load JSON file
with open("trivy_output.json", "r") as file:
data = json.load(file)
# Ensure the output directory exists
output_dir = "output"
os.makedirs(output_dir, exist_ok=True)
# Process each target (Library/File scanned)
for result in data.get("Results", []):
target_name = result.get("Target", "unknown_target").replace("/", "_").replace(":", "_")
output_file = os.path.join(output_dir, f"{target_name}.csv")
# Extract vulnerabilities for this target
records = []
for vuln in result.get("Vulnerabilities", []):
flattened_vuln = {"Target": target_name}
flattened_vuln.update(vuln) # Merge all vulnerability fields
records.append(flattened_vuln)
# Convert to DataFrame and save to CSV
if records:
df = pd.DataFrame(records)
df.to_csv(output_file, index=False)
print(f"CSV file saved: {output_file}")
else:
print(f"No vulnerabilities found for {target_name}, skipping file creation.")
print("All CSV files have been generated under 'output/' folder.")