blob: 780d79261b536e7da82d8baab4547df7f9bd20fe [file] [log] [blame]
Jeremy Ronquillo4ee31912021-06-21 14:19:37 -07001# SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
2#
3# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
4
5import json
6import urllib.request
7import time
8
9def main():
Abhinav Balla138abd62021-07-12 12:08:39 -070010 config = json.loads(open("aml_staging_config.json", 'r').read())
Jeremy Ronquillo4ee31912021-06-21 14:19:37 -070011
12 # set active edges
13 activeEdges = config['activeEdges']
14
15 # set refresh interval (seconds)
16 refreshInterval = config['refreshInterval']
17
18 # set url to fetch edge status from
19 url = config['url']
20
21 # for debugging
22 debug = config['debug']
23 debugCase = True
24
25 while True:
26 # fetch edge status
27 response = urllib.request.urlopen(url)
28 data = response.read()
29 edges = json.loads(data.decode('utf-8'))
30
31 allEdgesUp = True
32
33 # loop through all edges
34 for e in edges['edges']:
35 # only check active edges specified in config file
36 if e['name'] not in activeEdges:
37 continue
38
39 if isEdgeUp(e):
40 print(e['name'] + '\nok\n')
41 else:
42 print(e['name'] + '\nDOWN\n')
43 allEdgesUp = False
44
45 if allEdgesUp:
46 # Run Green Light Scene
47 # os.system("uiopen shortcuts://run-shortcut?name=edgeOK")
48 print("** All edges are up. **")
49 else:
50 # Run Red Light Scene
51 # os.system("uiopen shortcuts://run-shortcut?name=edgeDOWN")
52 print("** AT LEAST 1 EDGE IS DOWN! **")
53 print("Sleeping for " + str(refreshInterval) + " seconds...")
54
55 time.sleep(refreshInterval)
56
57def isEdgeUp(edge):
58 return edge['status']['control_plane'] == "connected" and \
59 edge['status']['user_plane'] == "connected"
60
61if __name__ == "__main__":
62 main()