Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
CJ = http.cookiejar.CookieJar()
OPENER = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(CJ))

loginUrl = (PROTOCOL + '://' + SERVER + '/omk/opCharts/login')
loginDict = {'username' : USERNAME , 'password' : USERPASS}
DATA = urllib.parse.urlencode(loginDict).encode("utf-8")
REQUEST = urllib.request.Request(loginUrl, DATA)
OPENER.open(REQUEST)

Query opCharts for Node Status

Code Block
nodeData = OPENER.open(PROTOCOL + '://' + SERVER + '/omk/opCharts/nodes.json')
nodeDecoded = nodeData.read().decode()
nodeList = json.loads(nodeDecoded)

Build Group Centric Data Structure

Code Block
groupStatus = {}

for n in nodeList:
    if n['group'] not in groupStatus:
        groupStatus[n['group']] = {'up' : 0, 'down' : 0}
        groupStatus[n['group']]['nodes'] = {}
    if n['nodedown'] == 'true':
        groupStatus[n['group']]['down'] += 1
    else:
        groupStatus[n['group']]['up'] += 1
    groupStatus[n['group']]['nodes'][n['name']] = {'name' : n['name'], 'location' : n['location'], 'type' : n['nodeType'], 'net' : n['netType'], 'role' : n['roleType'], 'status' : n['nodestatus']}