blob: 2912db9174f5b3c8ea1d1dd215509dd2ee4170ea [file] [log] [blame]
Sapan Bhatia214c64c2015-01-29 21:05:39 +00001from django.http import HttpResponse
2from monitor import driver
3from core.models import *
4import json
Scott Baker9f80ea02015-02-04 00:33:57 -08005import os
Sapan Bhatia214c64c2015-01-29 21:05:39 +00006import time
7
8def Observer(request):
Scott Baker9f80ea02015-02-04 00:33:57 -08009 if not os.path.exists('/tmp/observer_last_run'):
10 return HttpResponse(json.dumps({"health": ":-X", "time": time.time(), "comp": 0}))
11
Sapan Bhatia214c64c2015-01-29 21:05:39 +000012 t = time.time()
Scott Baker9f80ea02015-02-04 00:33:57 -080013 status_str = open('/tmp/observer_last_run','r').read()
Sapan Bhatia214c64c2015-01-29 21:05:39 +000014 d = json.loads(status_str)
15 comp = d['last_run'] + d['last_duration']*2 + 300
16 if comp>t:
17 d['health'] = ':-)'
18 else:
19 d['health'] = ':-X'
20 d['time'] = t
21 d['comp'] = comp
22
23 return HttpResponse(json.dumps(d))