From 668c39362ea07bd38defc8cfdf7981b461863b6b Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 12 Feb 2021 14:03:28 -0800 Subject: [PATCH] testing new methods of filtering/slicing/dicing the data --- .gitignore | 1 + generate_report.py | 24 +++++--- template.html | 138 ++++++++++----------------------------------- 3 files changed, 47 insertions(+), 116 deletions(-) diff --git a/.gitignore b/.gitignore index 58e4800..957da38 100644 --- a/.gitignore +++ b/.gitignore @@ -131,3 +131,4 @@ dmypy.json # Dont store CSV files or reports *.csv report.html +*.json diff --git a/generate_report.py b/generate_report.py index aede838..44c57cb 100644 --- a/generate_report.py +++ b/generate_report.py @@ -16,6 +16,7 @@ def run(): 'passes_by_sev': {}, 'fails_by_sev': {}, 'infos_by_sev': {}, + 'results_by_check_id': {} } with open('template.html') as f: @@ -43,6 +44,18 @@ def run(): d = csv_data[idx] t = totals + # Capture results summary + rs = 'results_summary' + rl = d['result'].lower() + if rs not in totals: + t[rs] = dict() + if rl not in t[rs]: + t[rs][rl] = list() + t[rs][rl].append(d) + + if d['title_id'] not in t['results_by_check_id']: + t['results_by_check_id'][d['title_id']] = csv_data[idx] + if d['account_id'] not in t['accounts']: t['accounts'].append(d['account_id']) @@ -51,19 +64,16 @@ def run(): 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) - l = d['severity'].lower() if l not in t['all_by_sev']: t['all_by_sev'][l] = list() if idx not in t['all_by_sev'][l]: t['all_by_sev'][l].append(idx) + # list(OrderedDict.fromkeys([x['severity'].lower() for x in data.values() if x['severity'].lower()])) + + # print(totals['results_summary']) + tpl = Template(tpl) rendered = tpl.render(data=csv_data, totals=totals) diff --git a/template.html b/template.html index 8957369..50ba42c 100644 --- a/template.html +++ b/template.html @@ -13,14 +13,17 @@ padding-top: 80px; max-width: 1400px; } - .bg-green { - background-color: rgba(102,178,102,.2); + .b-pass, .b-pass:focus, .b-pass:active { + color: black; + background-color: rgba(102,178,102,.2) !important; } - .bg-red { - background-color: rgba(255,76,76,.2); + .b-fail, .b-fail:focus, .b-fail:active { + color: black; + background-color: rgba(255,76,76,.2) !important; } - .bg-blue { - background-color: rgba(127,127,255,.2); + .b-info, .b-info:focus, .b-info:active { + color: black; + background-color: rgba(128,163,221,.2) !important; } .totals { display: inline-block; @@ -47,18 +50,14 @@

Findings

+ {% for res_type in totals['results_summary'] %}
-

-

-
+
@@ -74,97 +73,16 @@ - {% for i in totals['fails'] %} - {% set d = data[i] %} + {% for i in totals['results_summary'][res_type] %} - - - - - - - - - - {% endfor %} - -
{{ d['account_id'] }}{{ d['region'] | truncate(12) }}{{ d['title_id'] }}{{ d['title_text'] }}{{ d['notes'] }}{{ d['compliance'] }}{{ d['severity'] }}{{ d['service_name'] }}
-
-
-
-
-

- -

-
-
- - - - - - - - - - - - - - - {% for i in totals['infos'] %} - {% set d = data[i] %} - - - - - - - - - - - {% endfor %} - -
Account IDRegionIDTextNotesComplianceSeverityService Name
{{ d['account_id'] }}{{ d['region'] | truncate(12) }}{{ d['title_id'] }}{{ d['title_text'] }}{{ d['notes'] }}{{ d['compliance'] }}{{ d['severity'] }}{{ d['service_name'] }}
-
-
-
-
-

- -

-
-
- - - - - - - - - - - - - - - {% for i in totals['passes'] %} - {% set d = data[i] %} - - - - - - - - - + + + + + + + + {% endfor %} @@ -172,7 +90,9 @@ + {% endfor %} + @@ -196,13 +116,13 @@ var result_doughnut = new Chart(ctx, { type: 'doughnut', data: { - labels: ['Passes', 'Fails', 'Infos'], + labels: ['Pass', 'Fail', 'Info'], datasets: [{ label: '', data: [ - {{ totals['passes'] | length }}, - {{ totals['fails'] | length }}, - {{ totals['infos'] | length }} + {{ totals['results_summary']['pass'] | length }}, + {{ totals['results_summary']['fail'] | length }}, + {{ totals['results_summary']['info'] | length }} ], backgroundColor: [ 'rgba(102,178,102, 0.2)',
Account IDRegionIDTextNotesComplianceSeverityService Name
{{ d['account_id'] }}{{ d['region'] | truncate(12) }}{{ d['title_id'] }}{{ d['title_text'] }}{{ d['notes'] }}{{ d['compliance'] }}{{ d['severity'] }}{{ d['service_name'] }}{{ i['account_id'] }}{{ i['region'] | truncate(12) }}{{ i['title_id'] }}{{ i['title_text'] }}{{ i['notes'] }}{{ i['compliance'] }}{{ i['severity'] }}{{ i['service_name'] }}