Sapan Bhatia | 8e6f53d | 2015-01-29 21:05:39 +0000 | [diff] [blame] | 1 | from django.http import HttpResponse |
| 2 | from monitor import driver |
| 3 | from core.models import * |
| 4 | import json |
Scott Baker | 3c06fbc | 2015-02-04 00:33:57 -0800 | [diff] [blame] | 5 | import os |
Sapan Bhatia | 8e6f53d | 2015-01-29 21:05:39 +0000 | [diff] [blame] | 6 | import time |
| 7 | |
| 8 | def Observer(request): |
Scott Baker | 3c06fbc | 2015-02-04 00:33:57 -0800 | [diff] [blame] | 9 | if not os.path.exists('/tmp/observer_last_run'): |
| 10 | return HttpResponse(json.dumps({"health": ":-X", "time": time.time(), "comp": 0})) |
| 11 | |
Sapan Bhatia | 8e6f53d | 2015-01-29 21:05:39 +0000 | [diff] [blame] | 12 | t = time.time() |
Scott Baker | 3c06fbc | 2015-02-04 00:33:57 -0800 | [diff] [blame] | 13 | status_str = open('/tmp/observer_last_run','r').read() |
Sapan Bhatia | 8e6f53d | 2015-01-29 21:05:39 +0000 | [diff] [blame] | 14 | 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)) |