Added color coding and statistics to html logging

This commit is contained in:
Logan Lipke
2020-05-08 12:24:38 -07:00
parent 73ef96bfa0
commit cb284b0c29

View File

@@ -5,7 +5,7 @@ import time
sys.path.append('py-json') sys.path.append('py-json')
import json import json
import pprint import pprint
from datetime import date import datetime
from LANforge import LFRequest from LANforge import LFRequest
from LANforge import LFUtils from LANforge import LFUtils
@@ -160,8 +160,18 @@ for name in stations:
#create weblog for monitoring stations #create weblog for monitoring stations
webLog = "stationStressTestLog.html" curTime = datetime.datetime.now().strftime("%Y-%m-%d_%H%M")
f = open(webLog,"w") webLog = "/home/lanforge/Documents/load-test/loadTest{}.html".format(curTime)
try:
f = open(webLog,"w")
except IOError as err:
print(err)
print("Please ensure correct permissions have been assigned in target directory")
sys.exit()
top = """<html> top = """<html>
<head> <head>
<title>Test report</title> <title>Test report</title>
@@ -171,29 +181,31 @@ h1, h2, h3 { text-align: center; font-family: "Century Gothic",Arial,Helvetica,s
</style> </style>
</head> </head>
<body> <body>
<h1>Long test on {}</h1> <h1>Long test on %s</h1>
<table> <table>
""".format(date.today()) """ % datetime.date.today()
f.write(top) f.write(top)
f.close() f.close()
f = open(webLog, "a")
f.write("<tr>\n")
for name in radios:
f.write("<th>{}</th>\n".format(name))
for min5 in range(1): f.write("</tr>\n")
print("Logging Info to {}".format(webLog))
for min5 in range(3):
f.write("<tr>")
for radio, numStations in radios.items(): for radio, numStations in radios.items():
#print(radio)
f = open(webLog, "a")
f.write("<tr>\n")
f.write("<th>{}</th>\n".format(radio))
f.write("</tr>\n")
withoutIP = 0 withoutIP = 0
dissociated = 0 dissociated = 0
good = 0
f.write("<tr>")
for i in range(0,numStations): for i in range(0,numStations):
staName = "sta" + radio[-1:] + str(paddingNum + i)[1:] staName = "sta" + radio[-1:] + str(paddingNum + i)[1:]
staStatus = getJsonInfo(mgrURL, "port/1/1/" + staName) staStatus = getJsonInfo(mgrURL, "port/1/1/" + staName)
@@ -201,19 +213,23 @@ for min5 in range(1):
withoutIP += 1 withoutIP += 1
if staStatus['interface']['ap'] == None: if staStatus['interface']['ap'] == None:
dissociated += 1 dissociated += 1
else:
good += 1
if withoutIP and not dissociated:
f.write("<td style=\"background-color:rgb(255,200,0);\">{}/{}</td>".format(good,numStations)) #without IP assigned
elif dissociated:
f.write("<td style=\"background-color:rgb(255,0,0);\">{}/{}</td>".format(good,numStations)) #dissociated from AP
else:
f.write("<td style=\"background-color:rgb(0,255,0);\">{}/{}</td>".format(good,numStations)) #with IP and associated
f.write("<td>\n")
f.write("<td>{}</td>".format(staName))
f.write("</td>\n")
f.write("</tr>") f.write("</tr>")
time.sleep((min5 + 1) * 30) #Sleeps for five minutes at a time per loop
f.write("</table></body></html>\n")
f.close()
#print("Without IP: {}".format(withoutIP)) f.write("</table></body></html>\n")
#print("Dissociated: {}".format(dissociated)) f.close()
time.sleep((min5 + 1) * 300) #Sleeps for five minutes at a time per loop
print("Stopping CX Traffic") print("Stopping CX Traffic")
for name in stations: for name in stations:
@@ -223,6 +239,7 @@ for name in stations:
time.sleep(10) time.sleep(10)
#remove all created stations and cross connects #remove all created stations and cross connects
print("Cleaning Up...") print("Cleaning Up...")
for staName in stations: for staName in stations:
reqURL = "cli-json/rm_vlan" reqURL = "cli-json/rm_vlan"