Commit 392ad25a authored by Elia Ponzio's avatar Elia Ponzio
Browse files

Update delta function

parent 48bef770
......@@ -19,40 +19,22 @@ def check_ping(host, timeout, **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:
success = True
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()
else:
return_value = "Failure to Ping!"
obj, created = Delta.objects.get_or_create(task=parent_task, success=False,
return_value=return_value)
success = False
return_value = "Failed to Ping!"
if not obj.success:
obj.save()
else:
obj.success = False
obj.save()
check_delta(success, return_value, parent_task)
print("Updated delta for " + parent_task.name)
@shared_task
def check_http(host, timeout, httpcode, **kwargs):
"""This Check will verify a HTTP endpoint. You are required to pass the task_id within the kwargs.
Variables: host (Domain or IP) and timeout (Seconds), httpcode (Expected response).
"""
parent_task = PeriodicTask.objects.get(id=kwargs['task_id'])
......@@ -88,3 +70,37 @@ def check_http(host, timeout, httpcode, **kwargs):
#@shared_task
# def l4_check():
# pass
def check_delta(responsebool, return_value, parent_task):
if responsebool:
delta = Delta.objects.filter(task=parent_task).last()
if not delta:
delta = Delta.objects.create(task=parent_task, success=True)
if delta.success:
delta.save()
else:
new_delta = Delta()
new_delta.task = parent_task
new_delta.success = True
new_delta.return_value = return_value
new_delta.save()
print("Status Changed for " + parent_task.name + " to a Success! Sending Notification")
#TODO put notification task
else:
delta = Delta.objects.filter(task=parent_task).last()
if not delta:
delta = Delta.objects.create(task=parent_task, success=False)
if not delta.success:
delta.save()
else:
new_delta = Delta()
new_delta.task = parent_task
new_delta.success = False
new_delta.return_value = return_value
new_delta.save()
print("Status Changed for " + parent_task.name + " to a Failure! Sending Notification")
#TODO put notification task
......@@ -25,10 +25,6 @@ def debug_task(self):
print(f'Request: {self.request!r}')
@app.task()
def l4_check():
pass
@app.task()
def notify_email(checkTask, receiver):
print("Sending email from task " + checkTask + " to " + receiver)
......
......@@ -4,3 +4,4 @@ django-celery-beat==2.2.0
Django==3.2.4
django-cockroachdb>=3.2.1
psycopg2==2.9.1
requests==2.25.1
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