...
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']} |
Loop Through The Data Building Tables
Code Block |
---|
print('Content-type: text/html\n\n') print('<html><style>') print('table, th, td { border: 1px solid black; border-collapse: collapse;}</style>') print('<head><title>Opmantek Network Status</title></head><body><strong>Opmantek Network Status</strong><br><br>') print('<table><tr><th>Group</th><th>Nodes Up</th><th>Nodes Down</th></tr>') for k in sorted(groupStatus): print('<tr><td>' + k + '</td><td> ' + str(groupStatus[k]['up']) + '</td><td> ' + str(groupStatus[k]['down']) + '</td></tr>') print('</table><br><br>') for k in sorted(groupStatus): print('<strong>Group: ' + k + '</strong><br>') print('<table><tr><th>Node</th><th>Location</th><th>Type</th><th>Net</th><th>Role</th><th>Status</th></tr>') for g in sorted(groupStatus[k]['nodes']): print('<tr><td>' + groupStatus[k]['nodes'][g]['name'] + '</td><td> ' + groupStatus[k]['nodes'][g]['location'] + ' </td><td> ' + groupStatus[k]['nodes'][g]['type'] + ' </td><td> ' + groupStatus[k]['nodes'][g]['net'] + ' </td><td> ' + groupStatus[k]['nodes'][g]['role'] + ' </td><td> ' + groupStatus[k]['nodes'][g]['status'] + ' </td>') print('</table><br><br>') print('</html>') |