-
Notifications
You must be signed in to change notification settings - Fork 7
/
converter.py
33 lines (26 loc) · 885 Bytes
/
converter.py
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 csv
import json
# Set variables for within container
CSV_PATH = 'prowler_report.csv'
JSON_PATH = 'prowler_report.json'
# Reads prowler CSV output
csv_file = csv.DictReader(open(CSV_PATH, 'r'))
# Create empty JSON list, read out rows from CSV into it
json_list = []
for row in csv_file:
json_list.append(row)
# Writes row into JSON file, writes out to docker from .dumps
open(JSON_PATH, 'w').write(json.dumps(json_list))
# open newly converted prowler output
with open('prowler_report.json') as f:
data = json.load(f)
# remove data not needed for Security Hub BatchImportFindings
for element in data:
del element['PROFILE']
del element['SCORED']
del element['LEVEL']
del element['ACCOUNT_NUM']
del element['REGION']
# writes out to a new file, prettified
with open('format_prowler_report.json', 'w') as f:
json.dump(data, f, indent=2)