-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.py
36 lines (26 loc) · 853 Bytes
/
monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import RPi.GPIO as GPIO
host = "184.72.235.230"
port = "8080"
jobs = ["develop mangrove","develop-Datawinners", "develop-Datawinners-Smoke_Test", "develop-Datawinners_functional_test"]
RED_PIN = 24
GREEN_PIN = 26
GPIO.setmode(GPIO.BOARD)
GPIO.setup(GREEN_PIN, GPIO.OUT)
GPIO.setup(RED_PIN, GPIO.OUT)
def get_result(job_name):
resp = requests.get('http://%s:%s/job/%s/lastBuild/api/json'%(host, port, job_name))
json = resp.json if isinstance(resp.json, dict) else resp.json() #older requests version had json as property
return json.get('result')
def set_status(r,g):
GPIO.output(RED_PIN, r)
GPIO.output(GREEN_PIN, g)
result = [get_result(job_name) for job_name in jobs]
if "FAILURE" in result:
set_status(1,0)
elif None in result:
pass
elif set(result) == set(["SUCCESS"]):
set_status(0,1)
else:
set_status(0,0)