blob: 2912db9174f5b3c8ea1d1dd215509dd2ee4170ea [file] [log] [blame]
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +00001from django.http import HttpResponse
2from monitor import driver
3from core.models import *
4import json
Scott Baker3c06fbc2015-02-04 00:33:57 -08005import os
Sapan Bhatia8e6f53d2015-01-29 21:05:39 +00006import time
7
8def Observer(request):
Scott Baker3c06fbc2015-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 Bhatia8e6f53d2015-01-29 21:05:39 +000012 t = time.time()
Scott Baker3c06fbc2015-02-04 00:33:57 -080013 status_str = open('/tmp/observer_last_run','r').read()
Sapan Bhatia8e6f53d2015-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))