diff --git a/abstracts/comparison_methods.py b/abstracts/comparison_methods.py index 2618058..4a8879a 100644 --- a/abstracts/comparison_methods.py +++ b/abstracts/comparison_methods.py @@ -31,11 +31,13 @@ def init(self, **kwargs): """ - def log(self, green_txt, normal_txt, log_to_results_file=True, end="\n"): + def log(self, colored_txt, normal_txt, log_to_results_file=True, + end="\n", error=False): """ gives the txt to the logger to log it to stdout and results.txt """ - self.notify_observers((normal_txt, green_txt, log_to_results_file, end)) + self.notify_observers( + (normal_txt, colored_txt, log_to_results_file, end, error)) def __del__(self): diff --git a/abstracts/dbs.py b/abstracts/dbs.py index ddf257f..1ba1f5c 100644 --- a/abstracts/dbs.py +++ b/abstracts/dbs.py @@ -37,11 +37,15 @@ def __init__( self.connect() self.init() - def log(self, green_txt, normal_txt, log_to_results_file=True, end="\n"): + def log(self, colored_txt, normal_txt, log_to_results_file=True, + end="\n", + error=False): """ gives the txt to the logger to log it to stdout and results.txt """ - self.notify_observers((normal_txt, green_txt, log_to_results_file, end)) + self.notify_observers(( + normal_txt, colored_txt, log_to_results_file, end, error + )) def connect(self): diff --git a/main.py b/main.py index 151ce0c..d754ecf 100644 --- a/main.py +++ b/main.py @@ -95,10 +95,10 @@ def setup_output_dir(self): return output_dir - def log(self, green_txt, normal_txt, log_to_results_file=True, + def log(self, colored_txt, normal_txt, log_to_results_file=True, end="\n", error=False): self.notify_observers( - (normal_txt, green_txt, log_to_results_file, end, error) + (normal_txt, colored_txt, log_to_results_file, end, error) ) @@ -117,7 +117,7 @@ def print_stats(self, print_stats_event): now = current_datetime.strftime('%Y-%m-%d %H:%M:%S') to_print = f"{now} - Total parsed flows by " for tool in self.supported_tools: - to_print += f"{tool}: {self.db.get_flows_parsed('slips')}" + to_print += f"{tool}: {self.db.get_flows_parsed('slips')} " print(to_print, end='\r') def get_human_readable_datetime(self) -> str: @@ -235,6 +235,9 @@ def main(self): all_good: bool = tools_parser.start_parsers() if not all_good: + self.log("", + "Problem occurred with parsers. Stopping.", + error=True) return # now that the parsers ended don't print more stats diff --git a/metrics/calculator.py b/metrics/calculator.py index ba78469..36f7463 100644 --- a/metrics/calculator.py +++ b/metrics/calculator.py @@ -28,8 +28,12 @@ def __init__( self.tool = tool - def log(self, green_txt, normal_txt, log_to_results_file=True, end="\n"): - self.notify_observers((normal_txt, green_txt, log_to_results_file, end)) + def log(self, colored_txt, normal_txt, log_to_results_file=True, + end="\n", + error=False): + self.notify_observers(( + normal_txt, colored_txt, log_to_results_file, end, error + )) def confusion_matrix(self, labels: Iterator): """ diff --git a/parsers/suricata.py b/parsers/suricata.py index 85067c8..9b73a50 100644 --- a/parsers/suricata.py +++ b/parsers/suricata.py @@ -140,7 +140,7 @@ def parse(self): if 'malicious' in label.lower(): self.label_tw(timestamp, line['src_ip'], 'malicious') - self.print_stats() + self.print_stats() os._exit(0) except Exception as e: self.log("An error occurred: ", e, error=True)