Jeremy Ronquillo | 4ee3191 | 2021-06-21 14:19:37 -0700 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org> |
| 2 | # |
| 3 | # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0 |
| 4 | |
| 5 | import json |
| 6 | import urllib.request |
| 7 | import time |
| 8 | |
| 9 | def main(): |
Abhinav Balla | 138abd6 | 2021-07-12 12:08:39 -0700 | [diff] [blame] | 10 | config = json.loads(open("aml_staging_config.json", 'r').read()) |
Jeremy Ronquillo | 4ee3191 | 2021-06-21 14:19:37 -0700 | [diff] [blame] | 11 | |
| 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 | |
| 57 | def isEdgeUp(edge): |
| 58 | return edge['status']['control_plane'] == "connected" and \ |
| 59 | edge['status']['user_plane'] == "connected" |
| 60 | |
| 61 | if __name__ == "__main__": |
| 62 | main() |