testing new methods of filtering/slicing/dicing the data

refactoring
lza_menace 3 years ago
parent 9ab22fb6b9
commit 668c39362e

1
.gitignore vendored

@ -131,3 +131,4 @@ dmypy.json
# Dont store CSV files or reports # Dont store CSV files or reports
*.csv *.csv
report.html report.html
*.json

@ -16,6 +16,7 @@ def run():
'passes_by_sev': {}, 'passes_by_sev': {},
'fails_by_sev': {}, 'fails_by_sev': {},
'infos_by_sev': {}, 'infos_by_sev': {},
'results_by_check_id': {}
} }
with open('template.html') as f: with open('template.html') as f:
@ -43,6 +44,18 @@ def run():
d = csv_data[idx] d = csv_data[idx]
t = totals 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']: if d['account_id'] not in t['accounts']:
t['accounts'].append(d['account_id']) t['accounts'].append(d['account_id'])
@ -51,19 +64,16 @@ def run():
t['scan_results'].append(idx) 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() l = d['severity'].lower()
if l not in t['all_by_sev']: if l not in t['all_by_sev']:
t['all_by_sev'][l] = list() t['all_by_sev'][l] = list()
if idx not in t['all_by_sev'][l]: if idx not in t['all_by_sev'][l]:
t['all_by_sev'][l].append(idx) 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) tpl = Template(tpl)
rendered = tpl.render(data=csv_data, totals=totals) rendered = tpl.render(data=csv_data, totals=totals)

@ -13,14 +13,17 @@
padding-top: 80px; padding-top: 80px;
max-width: 1400px; max-width: 1400px;
} }
.bg-green { .b-pass, .b-pass:focus, .b-pass:active {
background-color: rgba(102,178,102,.2); color: black;
background-color: rgba(102,178,102,.2) !important;
} }
.bg-red { .b-fail, .b-fail:focus, .b-fail:active {
background-color: rgba(255,76,76,.2); color: black;
background-color: rgba(255,76,76,.2) !important;
} }
.bg-blue { .b-info, .b-info:focus, .b-info:active {
background-color: rgba(127,127,255,.2); color: black;
background-color: rgba(128,163,221,.2) !important;
} }
.totals { .totals {
display: inline-block; display: inline-block;
@ -47,18 +50,14 @@
<div class="row"> <div class="row">
<h2>Findings</h2> <h2>Findings</h2>
<div class="accordion" id="accordion"> <div class="accordion" id="accordion">
{% for res_type in totals['results_summary'] %}
<div class="accordion-item"> <div class="accordion-item">
<h2 class="accordion-header" id="headingOne"> <h2 class="accordion-header" id="heading{{ loop.index }}">
<button class="accordion-button collapsed bg-red" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne"> <button class="accordion-button collapsed b-{{ res_type }}" type="button" data-bs-toggle="collapse" data-bs-target="#collapse{{ loop.index }}" aria-expanded="false" aria-controls="collapse{{ loop.index }}">
Fails (<strong>{{ totals['fails'] | length }} total</strong>{# , {{ res_type | capitalize }} (<strong>{{ totals['results_summary'][res_type] | length }} total</strong>)
{% for i in totals['all_by_sev'] %}
{{ totals['all_by_sev'][i] | length }}
{% if i == '' %}unmarked{% else %}{{ i }}{% endif %}{% if not loop.last %}, {% endif %}
{% endfor %} #}
)
</button> </button>
</h2> </h2>
<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" data-bs-parent="#accordion"> <div id="collapse{{ loop.index }}" class="accordion-collapse collapse" aria-labelledby="heading{{ loop.index }}" data-bs-parent="#accordion">
<div class="accordion-body"> <div class="accordion-body">
<table class="table table-sm" data-toggle="table"> <table class="table table-sm" data-toggle="table">
<thead> <thead>
@ -74,97 +73,16 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for i in totals['fails'] %} {% for i in totals['results_summary'][res_type] %}
{% set d = data[i] %}
<tr> <tr>
<td>{{ d['account_id'] }}</td> <td>{{ i['account_id'] }}</td>
<td>{{ d['region'] | truncate(12) }}</td> <td>{{ i['region'] | truncate(12) }}</td>
<td>{{ d['title_id'] }}</td> <td>{{ i['title_id'] }}</td>
<td><strong>{{ d['title_text'] }}</strong></td> <td><strong>{{ i['title_text'] }}</strong></td>
<td>{{ d['notes'] }}</td> <td>{{ i['notes'] }}</td>
<td>{{ d['compliance'] }}</td> <td>{{ i['compliance'] }}</td>
<td>{{ d['severity'] }}</td> <td>{{ i['severity'] }}</td>
<td>{{ d['service_name'] }}</td> <td>{{ i['service_name'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button class="accordion-button collapsed bg-blue" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Infos (<strong>{{ totals['infos'] | length }} total</strong>)
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordion">
<div class="accordion-body">
<table class="table table-sm" data-toggle="table">
<thead>
<tr>
<th data-sort="int">Account ID</th>
<th data-sort="string">Region</th>
<th data-sort="string">ID</th>
<th data-sort="string">Text</th>
<th data-sort="string">Notes</th>
<th data-sort="string">Compliance</th>
<th data-sort="string">Severity</th>
<th data-sort="string">Service Name</th>
</tr>
</thead>
<tbody>
{% for i in totals['infos'] %}
{% set d = data[i] %}
<tr>
<td>{{ d['account_id'] }}</td>
<td>{{ d['region'] | truncate(12) }}</td>
<td>{{ d['title_id'] }}</td>
<td><strong>{{ d['title_text'] }}</strong></td>
<td>{{ d['notes'] }}</td>
<td>{{ d['compliance'] }}</td>
<td>{{ d['severity'] }}</td>
<td>{{ d['service_name'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingThree">
<button class="accordion-button collapsed bg-green" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Passes (<strong>{{ totals['passes'] | length }} total</strong>)
</button>
</h2>
<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordion">
<div class="accordion-body">
<table class="table table-sm" data-toggle="table">
<thead>
<tr>
<th data-sort="int">Account ID</th>
<th data-sort="string">Region</th>
<th data-sort="string">ID</th>
<th data-sort="string">Text</th>
<th data-sort="string">Notes</th>
<th data-sort="string">Compliance</th>
<th data-sort="string">Severity</th>
<th data-sort="string">Service Name</th>
</tr>
</thead>
<tbody>
{% for i in totals['passes'] %}
{% set d = data[i] %}
<tr>
<td>{{ d['account_id'] }}</td>
<td>{{ d['region'] | truncate(12) }}</td>
<td>{{ d['title_id'] }}</td>
<td><strong>{{ d['title_text'] }}</strong></td>
<td>{{ d['notes'] }}</td>
<td>{{ d['compliance'] }}</td>
<td>{{ d['severity'] }}</td>
<td>{{ d['service_name'] }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -172,7 +90,9 @@
</div> </div>
</div> </div>
</div> </div>
{% endfor %}
</div> </div>
</div> </div>
</div> </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
@ -196,13 +116,13 @@
var result_doughnut = new Chart(ctx, { var result_doughnut = new Chart(ctx, {
type: 'doughnut', type: 'doughnut',
data: { data: {
labels: ['Passes', 'Fails', 'Infos'], labels: ['Pass', 'Fail', 'Info'],
datasets: [{ datasets: [{
label: '', label: '',
data: [ data: [
{{ totals['passes'] | length }}, {{ totals['results_summary']['pass'] | length }},
{{ totals['fails'] | length }}, {{ totals['results_summary']['fail'] | length }},
{{ totals['infos'] | length }} {{ totals['results_summary']['info'] | length }}
], ],
backgroundColor: [ backgroundColor: [
'rgba(102,178,102, 0.2)', 'rgba(102,178,102, 0.2)',

Loading…
Cancel
Save