Commit 7579f982 authored by Elia Ponzio's avatar Elia Ponzio
Browse files

Add http check

parent 392ad25a
......@@ -27,6 +27,7 @@ def check_ping(host, timeout, **kwargs):
success = False
return_value = "Failed to Ping!"
## Figure out if a delta occured, if not, update the last check time
check_delta(success, return_value, parent_task)
......@@ -37,34 +38,18 @@ def check_http(host, timeout, httpcode, **kwargs):
"""
parent_task = PeriodicTask.objects.get(id=kwargs['task_id'])
print("the parent task: " + parent_task.name)
## Figure out if a delta occured, if not, update the last check time
if response.returncode == 0:
return_value = "Success!"
obj, created = Delta.objects.get_or_create(task=parent_task, success=True,
return_value=return_value)
if obj.success:
obj.save()
else:
obj.success = True
obj.save()
r = requests.get(host, timeout=int(timeout))
if int(r.status_code) == int(httpcode):
success = True
return_value = "Success! Return code matches expected code " + str(httpcode)
else:
return_value = "Failure to Ping!"
obj, created = Delta.objects.get_or_create(task=parent_task, success=False,
return_value=return_value)
if not obj.success:
obj.save()
else:
obj.success = False
obj.save()
print("Updated delta for " + parent_task.name)
success = False
return_value = "Failure! Returned code: " + str(r.status_code) + ", expected code: " + str(httpcode)
check_delta(success, return_value, parent_task)
## TODO
#@shared_task
......@@ -79,6 +64,8 @@ def check_delta(responsebool, return_value, parent_task):
delta = Delta.objects.create(task=parent_task, success=True)
if delta.success:
delta.return_value = return_value
delta.success = True
delta.save()
else:
new_delta = Delta()
......@@ -95,6 +82,8 @@ def check_delta(responsebool, return_value, parent_task):
delta = Delta.objects.create(task=parent_task, success=False)
if not delta.success:
delta.return_value = return_value
delta.success = False
delta.save()
else:
new_delta = Delta()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment