diff --git a/engines/tasks.py b/engines/tasks.py index c739eac1..c3d8603d 100644 --- a/engines/tasks.py +++ b/engines/tasks.py @@ -442,9 +442,20 @@ def startscan_task(self, params): scan.status = "error" scan.finished_at = timezone.now() scan.save() - Event.objects.create(message="[EngineTasks/startscan_task/{}] AfterScan - something goes wrong in 'getfindings' call (request_status_code={}). Task aborted.".format(self.request.id, resp.status_code), - type="ERROR", severity="ERROR", scan=scan, description="{}".format(resp.text)) + response_reason = "Undefined" + + if 'details' in json.loads(resp.text) and 'reason' in json.loads(resp.text)['details']: + response_reason = json.loads(resp.text)['details']['reason'] + elif 'reason' in json.loads(resp.text): + response_reason = json.loads(resp.text)['reason'] + + Event.objects.create(message="[EngineTasks/startscan_task/{}] AfterScan - something goes wrong" + " in 'getfindings' call (response_status_code={}, response_status={}, " + "response_details={}). Task aborted.".format(self.request.id, + resp.status_code,json.loads(resp.text)['status'], response_reason), + type="ERROR", severity="ERROR", scan=scan, description="{}".format(resp.text)) return False + except Exception as e: scan.status = "error" scan.finished_at = timezone.now() @@ -583,7 +594,7 @@ def start_periodic_scan_task(self, params): retries -= 1 if retries == 0: - print("ERROR: start_periodicscan_task/beforescan - max_retries ({}) reached.".format(retries)) + print("ERROR: start_periodicscan_task/beforescan - max_retries ({}) reached.".format(NB_MAX_RETRIES)) return False # -2- call the engine REST API /startscan @@ -622,7 +633,7 @@ def start_periodic_scan_task(self, params): print("status: {}".format(scan_status)) if retries == 0: - print("ERROR: startscan_task/scaninprogress - max_retries ({}) reached.".format(retries)) + print("ERROR: startscan_task/scaninprogress - max_retries ({}) reached.".format(NB_MAX_RETRIES)) return False # Todo: change to wait the report becomes available