diff --git a/generate_report.py b/generate_report.py index 821003e..b22a1e8 100644 --- a/generate_report.py +++ b/generate_report.py @@ -5,12 +5,21 @@ from csv import reader def run(): csv_data = {} + totals = { + 'accounts': [], + 'regions': [], + 'scan_results': [], + 'passes': [], + 'fails': [], + 'infos': [] + } with open('template.html') as f: tpl = f.read() with open('prowler-test.csv') as csv_file: csv_reader = reader(csv_file, delimiter=',') + next(csv_reader, None) for idx, row in enumerate(csv_reader): csv_data[idx] = { 'profile': row[0], @@ -27,8 +36,26 @@ def run(): 'service_name': row[11], } + d = csv_data[idx] + t = totals + + if d['account_id'] not in t['accounts']: + t['accounts'].append(d['account_id']) + + if d['region'] not in t['regions']: + t['regions'].append(d['region']) + + t['scan_results'].append(idx) + + if d['result'] == 'PASS': + t['passes'].append(idx) + elif d['result'] == 'FAIL': + t['fails'].append(idx) + elif d['result'] == 'INFO': + t['infos'].append(idx) + t = Template(tpl) - rendered = t.render(data=csv_data) + rendered = t.render(data=csv_data, totals=totals) with open('report.html', 'w') as f: f.write(rendered) diff --git a/template.html b/template.html index b856674..c60e585 100644 --- a/template.html +++ b/template.html @@ -6,20 +6,69 @@
-

Loop through the list:

-