From b3c0e922bbd99be4b1dab57ec3402a08162b34c2 Mon Sep 17 00:00:00 2001 From: karamchandan <amit.kbatra@alumnos.upm.es> Date: Thu, 13 Jul 2023 13:47:19 +0200 Subject: [PATCH] Cleanup of the DAD service implementation --- .../service/l3_distributedattackdetector.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/l3_distributedattackdetector/service/l3_distributedattackdetector.py b/src/l3_distributedattackdetector/service/l3_distributedattackdetector.py index 52cdb0c09..e87636952 100644 --- a/src/l3_distributedattackdetector/service/l3_distributedattackdetector.py +++ b/src/l3_distributedattackdetector/service/l3_distributedattackdetector.py @@ -81,9 +81,9 @@ class l3_distributedattackdetector: with grpc.insecure_channel(CENTRALIZED_ATTACK_DETECTOR) as channel: self.cad = L3CentralizedattackdetectorStub(channel) - LOGGER.info("Connected to the centralized attack detector") - - LOGGER.info("Obtaining features...") + LOGGER.info("Connected to the Centralized Attack Detector") + + LOGGER.info("Obtaining features Ids. from the Centralized Attack Detector...") self.feature_ids = self.get_features_ids() LOGGER.info("Features Ids.: {:s}".format(str(self.feature_ids))) @@ -118,10 +118,10 @@ class l3_distributedattackdetector: # start an infinite loop while True: - # read last line of file + # read last line of the file line = file.readline() - # sleep if file hasn't been updated + # sleep if the file hasn't been updated if not line: time.sleep(time_sleep) continue @@ -135,16 +135,19 @@ class l3_distributedattackdetector: yield line - def load_file(self, dirname=TSTAT_DIR_NAME): # - Client side - + def load_file(self, dirname=TSTAT_DIR_NAME): while True: here = os.path.dirname(os.path.abspath(__file__)) tstat_piped = os.path.join(here, dirname) tstat_dirs = os.listdir(tstat_piped) + if len(tstat_dirs) > 0: tstat_dirs.sort() new_dir = tstat_dirs[-1] tstat_file = tstat_piped + new_dir + "/log_tcp_temp_complete" + LOGGER.info("Following: {:s}".format(str(tstat_file))) + return tstat_file else: LOGGER.info("No Tstat directory!") @@ -165,7 +168,7 @@ class l3_distributedattackdetector: feature = feature_id - 1 values.append(float(line[feature])) except IndexError: - print("IndexError: {0}".format(line)) + LOGGER.error("IndexError: {0}".format(line)) return values -- GitLab