blob: 249c09f3926a72f19f0ca723acfe32c1112d4f93 [file] [log] [blame]
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +00001from django.http import HttpResponse
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +00002from core.models import *
Sapan Bhatia99fb3e72016-03-24 07:56:38 +01003from xos.config import Config
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +00004import json
Scott Baker3c06fbc2015-02-04 00:33:57 -08005import os
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +00006import time
7
8def Observer(request):
Sapan Bhatia99fb3e72016-03-24 07:56:38 +01009 diag = Diag.objects.filter(name=Config().observer_name).first()
10 if not diag:
Scott Baker3c06fbc2015-02-04 00:33:57 -080011 return HttpResponse(json.dumps({"health": ":-X", "time": time.time(), "comp": 0}))
12
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +000013 t = time.time()
Sapan Bhatia99fb3e72016-03-24 07:56:38 +010014
15 d = json.loads(diag.backend_register)
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +000016 comp = d['last_run'] + d['last_duration']*2 + 300
17 if comp>t:
18 d['health'] = ':-)'
19 else:
20 d['health'] = ':-X'
21 d['time'] = t
22 d['comp'] = comp
23
24 return HttpResponse(json.dumps(d))