Skip to content

Commit

Permalink
add optional reason message in AfterScan
Browse files Browse the repository at this point in the history
  • Loading branch information
contact@grandville.net committed Jun 16, 2020
1 parent 7646584 commit afc1745
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions engines/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit afc1745

Please sign in to comment.