Skip to content
Snippets Groups Projects
Commit 1ee965f9 authored by penenadpi's avatar penenadpi Committed by Anze Luzar
Browse files

Added total scan execution time to JSON

parent 8f84ca33
Branches
No related tags found
No related merge requests found
...@@ -227,7 +227,7 @@ class ResultsSummary: ...@@ -227,7 +227,7 @@ class ResultsSummary:
for scan in self.outcomes: for scan in self.outcomes:
if not(scan == "uuid") and not(scan == "time") and not(scan == "archive") and self.outcomes[scan]["status"] == "Problems": if not(scan == "uuid") and not(scan == "time") and not(scan == "archive") and not(scan == "execution-duration") and self.outcomes[scan]["status"] == "Problems":
html_page = html_page + "<tr>" html_page = html_page + "<tr>"
html_page = html_page + "<td>" + scan + "</td>" html_page = html_page + "<td>" + scan + "</td>"
...@@ -239,7 +239,7 @@ class ResultsSummary: ...@@ -239,7 +239,7 @@ class ResultsSummary:
for scan in self.outcomes: for scan in self.outcomes:
if not(scan == "uuid") and not(scan == "time") and not(scan == "archive") and self.outcomes[scan]["status"] == "Passed": if not(scan == "uuid") and not(scan == "time") and not(scan == "archive") and not(scan == "execution-duration") and self.outcomes[scan]["status"] == "Passed":
html_page = html_page + "<tr>" html_page = html_page + "<tr>"
html_page = html_page + "<td>" + scan + "</td>" html_page = html_page + "<td>" + scan + "</td>"
html_page = html_page + "<td bgcolor='green'>" + str(self.outcomes[scan]["status"]) + "</td>" html_page = html_page + "<td bgcolor='green'>" + str(self.outcomes[scan]["status"]) + "</td>"
...@@ -250,7 +250,7 @@ class ResultsSummary: ...@@ -250,7 +250,7 @@ class ResultsSummary:
for scan in self.outcomes: for scan in self.outcomes:
if not(scan=="uuid") and not(scan=="time") and not(scan == "archive") and self.outcomes[scan]["status"] == "Info" : if not(scan=="uuid") and not(scan=="time") and not(scan == "archive") and not(scan == "execution-duration") and self.outcomes[scan]["status"] == "Info" :
html_page = html_page + "<tr>" html_page = html_page + "<tr>"
html_page = html_page + "<td>" + scan + "</td>" html_page = html_page + "<td>" + scan + "</td>"
html_page = html_page + "<td bgcolor='yellow'>" + str(self.outcomes[scan]["status"]) + "</td>" html_page = html_page + "<td bgcolor='yellow'>" + str(self.outcomes[scan]["status"]) + "</td>"
...@@ -261,7 +261,7 @@ class ResultsSummary: ...@@ -261,7 +261,7 @@ class ResultsSummary:
for scan in self.outcomes: for scan in self.outcomes:
if not(scan=="uuid") and not(scan=="time") and not(scan == "archive") and self.outcomes[scan]["status"] == "No files" : if not(scan=="uuid") and not(scan=="time") and not(scan == "archive") and not(scan == "execution-duration") and self.outcomes[scan]["status"] == "No files" :
html_page = html_page + "<tr>" html_page = html_page + "<tr>"
html_page = html_page + "<td>" + scan + "</td>" html_page = html_page + "<td>" + scan + "</td>"
html_page = html_page + "<td bgcolor='gray'>" + str(self.outcomes[scan]["status"]) + "</td>" html_page = html_page + "<td bgcolor='gray'>" + str(self.outcomes[scan]["status"]) + "</td>"
......
...@@ -45,6 +45,7 @@ import uuid ...@@ -45,6 +45,7 @@ import uuid
import os import os
import json import json
from datetime import datetime from datetime import datetime
import time
class ScanRunner: class ScanRunner:
def __init__(self): def __init__(self):
...@@ -141,6 +142,7 @@ class ScanRunner: ...@@ -141,6 +142,7 @@ class ScanRunner:
:param scan_response_type: Scan response type (JSON or HTML) :param scan_response_type: Scan response type (JSON or HTML)
:return: Dict or string with output for running checks :return: Dict or string with output for running checks
""" """
start_time = time.time()
random_uuid = str(uuid.uuid4()) random_uuid = str(uuid.uuid4())
# TODO: Replace this hardcoded path with a parameter # TODO: Replace this hardcoded path with a parameter
dir_name = "../outputs/logs/scan_run_" + random_uuid dir_name = "../outputs/logs/scan_run_" + random_uuid
...@@ -167,12 +169,14 @@ class ScanRunner: ...@@ -167,12 +169,14 @@ class ScanRunner:
non_compatible_checks.append(check.name) non_compatible_checks.append(check.name)
write_string_to_file(check.name, dir_name, "No files to scan") write_string_to_file(check.name, dir_name, "No files to scan")
self.results_summary.summarize_no_files(check.name) self.results_summary.summarize_no_files(check.name)
end_time = time.time()
duration = end_time-start_time
self.results_summary.generate_html_prioritized(random_uuid) self.results_summary.generate_html_prioritized(random_uuid)
self.results_summary.outcomes["uuid"] = random_uuid self.results_summary.outcomes["uuid"] = random_uuid
self.results_summary.outcomes["archive"] = self.archive_name self.results_summary.outcomes["archive"] = self.archive_name
self.results_summary.outcomes["time"] = datetime.now().strftime("%m/%d/%Y, %H:%M:%S") self.results_summary.outcomes["time"] = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
self.results_summary.outcomes["execution-duration"] = str(round(duration, 3))
self.results_summary.dump_outcomes(random_uuid) self.results_summary.dump_outcomes(random_uuid)
if(self.results_persistence.connection_problem == False and self.persistence_enabled == True): if(self.results_persistence.connection_problem == False and self.persistence_enabled == True):
...@@ -191,11 +195,14 @@ class ScanRunner: ...@@ -191,11 +195,14 @@ class ScanRunner:
write_string_to_file(iac_check.name, dir_name, "No files to scan") write_string_to_file(iac_check.name, dir_name, "No files to scan")
self.results_summary.summarize_no_files(iac_check.name) self.results_summary.summarize_no_files(iac_check.name)
end_time = time.time()
duration = end_time-start_time
self.results_summary.generate_html_prioritized(random_uuid) self.results_summary.generate_html_prioritized(random_uuid)
self.results_summary.outcomes["uuid"] = random_uuid self.results_summary.outcomes["uuid"] = random_uuid
self.results_summary.outcomes["archive"] = self.archive_name self.results_summary.outcomes["archive"] = self.archive_name
self.results_summary.outcomes["time"] = datetime.now().strftime("%m/%d/%Y, %H:%M:%S") self.results_summary.outcomes["time"] = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
self.results_summary.outcomes["execution-duration"] = str(round(duration, 3))
self.results_summary.dump_outcomes(random_uuid) self.results_summary.dump_outcomes(random_uuid)
if(self.results_persistence.connection_problem == False and self.persistence_enabled == True): if(self.results_persistence.connection_problem == False and self.persistence_enabled == True):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment