From 3db15529bd7d8f31c74fd82796dca709d2cf50f5 Mon Sep 17 00:00:00 2001 From: Gioacchino Vino <gioacchino.vino@infn.it> Date: Wed, 24 Apr 2024 17:21:33 +0200 Subject: [PATCH] Reviewed code --- files/gvm_library.py | 26 -------------------------- files/scan.py | 14 ++++---------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/files/gvm_library.py b/files/gvm_library.py index 0920834..8e6b81c 100644 --- a/files/gvm_library.py +++ b/files/gvm_library.py @@ -284,9 +284,6 @@ class Task: get_report_info = retrieves report information """ - # Configiration - COMMUNICATION_RETRIES = 3 - def __init__(self, client, name: str, @@ -405,29 +402,6 @@ class Task: def __del__(self): self.delete() - def qwe__get_info(self, filter: str) -> List[dict]: - res = [] - tasks = self.client.get_tasks(filter_string = filter) \ - .xpath('task') - for t in tasks: - t_name = str(t.xpath(GVM_XPATH_NAME_TEXT)[0]) - t_id = str(t.xpath(GVM_XPATH_ID)[0]) - t_in_use = str(t.xpath(GVM_XPATH_INUSE_TEXT)[0]) - t_status = str(t.xpath(GVM_XPATH_STATUS_TEXT_3)[0]) - t_dict = {"name": t_name, - "id": t_id, - "in_use": t_in_use, - "status": t_status} - try: - t_report_id = t.xpath(GVM_XPATH_LAST_REPORT_ID)[0] - except Exception: - pass - else: - t_dict['report_id'] = t_report_id - - res.append(t_dict) - return res - def update_status(self): task_info = self.client.get_tasks(filter_string = self.id) \ .xpath('task')[0] diff --git a/files/scan.py b/files/scan.py index 2dfb730..8e2f10c 100644 --- a/files/scan.py +++ b/files/scan.py @@ -128,15 +128,9 @@ for host,ports in endpoints.items(): else: reports[host] = {'global': {"severity": -1, "threat": f"Scan Error. task.id: {task.id}"} } - - for task in tasks: - gvm.get_client().delete_task(task.id) - -"""for task in tasks: - try: - del task - except Exception as e: - logging.error(f"Error during task deletion. Msg: {e.msg}") +for task in tasks: + del task + #gvm.get_client().delete_task(task.id) for target in targets: try: @@ -149,7 +143,7 @@ for port_list in port_lists: del port_list except Exception as e: logging.error(f"Error during port list deletion. Msg: {e.msg}") -""" + reports = process_global_reports_info(reports) logging.info(pretty_json(reports)) -- GitLab