Fixed some issues with timing and json requests, changed color scheme for reports

This commit is contained in:
Logan Lipke
2020-05-11 13:09:25 -07:00
parent bb105c2f16
commit 5abcc66ba2

View File

@@ -11,17 +11,21 @@ from LANforge import LFUtils
import argparse import argparse
import re import re
import math import math
import string
debugOn = False
def jsonReq(mgrURL, reqURL, data, debug=False): def jsonReq(mgrURL, reqURL, data, debug=False):
lf_r = LFRequest.LFRequest(mgrURL + reqURL) lf_r = LFRequest.LFRequest(mgrURL + reqURL)
lf_r.addPostData(data) lf_r.addPostData(data)
if debug: if debug:
json_response = lf_r.jsonPost(True) json_response = lf_r.jsonPost(debug)
LFUtils.debug_printer.pprint(json_response) LFUtils.debug_printer.pprint(json_response)
sys.exit(1) sys.exit(1)
else: else:
lf_r.jsonPost() lf_r.jsonPost(debug)
def execWrap(cmd): def execWrap(cmd):
@@ -31,56 +35,59 @@ def execWrap(cmd):
def getJsonInfo(mgrURL, reqURL): def getJsonInfo(mgrURL, reqURL):
lf_r = LFRequest.LFRequest(mgrURL + reqURL) lf_r = LFRequest.LFRequest(mgrURL + reqURL)
json_response = lf_r.getAsJson() json_response = lf_r.getAsJson(debugOn)
return json_response return json_response
parser = argparse.ArgumentParser(description="create max stations for each radio")
parser.add_argument("--test_duration", type=str, help="full duration for the test to run. should be specified by a number followed by a character. d for days, h for hours, m for minutes, s for seconds") parser = argparse.ArgumentParser(description="Create max stations for each radio")
parser.add_argument("--report_interval", type=str, help="how often a report is made. should be specified by a number followed by a character. d for days, h for hours, m for minutes, s for seconds") parser.add_argument("--test_duration", type=str, help="Full duration for the test to run. should be specified by a number followed by a character. d for days, h for hours, m for minutes, s for seconds")
parser.add_argument("--output_dir", type=str, help="directory to ouptut to") parser.add_argument("--report_interval", type=str, help="How often a report is made. should be specified by a number followed by a character. d for days, h for hours, m for minutes, s for seconds")
parser.add_argument("--output_prefix", type=str, help="name of the file. Timestamp will be appended to the end") parser.add_argument("--output_dir", type=str, help="Directory to ouptut to")
parser.add_argument("--output_prefix", type=str, help="Name of the file. Timestamp and .html will be appended to the end")
args = None args = None
try: try:
args = parser.parse_args() args = parser.parse_args()
if (args.test_duration is not None): if (args.test_duration is not None):
pattern = re.compile("^(\d+)([dhms])$") pattern = re.compile("^(\d+)([dhms]$)")
td = pattern.match(args.test_duration) td = pattern.match(args.test_duration)
if td != None: if td != None:
durTime = int(td.group(1)) durTime = int(td.group(1))
durMeasure = td.group(2) durMeasure = str(td.group(2))
if durMeasure == 'd':
duration = durTime * 60 * 60 * 24 if durMeasure == "d":
elif durMeasure == 'h': durationSec = durTime * 60 * 60 * 24
duration = durTime * 60 * 60 elif durMeasure == "h":
elif durMeasure == 'm': durationSec = durTime * 60 * 60
duration = durTime * 60 elif durMeasure == "m":
durationSec = durTime * 60
else: else:
duration = durMeasure durationSec = durMeasure
else: else:
parser.print_help() parser.print_help()
parser.exit() parser.exit()
if (args.report_interval is not None): if (args.report_interval is not None):
pattern = re.compile("^(\d+)([dhms])$") pattern = re.compile("^(\d+)([dhms])$")
td = pattern.match(args.report_interval) ri = pattern.match(args.report_interval)
if td != None: if ri != None:
intTime = int(td.group(1)) intTime = int(ri.group(1))
intMeasure = td.group(2) intMeasure = str(ri.group(2))
if intMeasure == 'd':
interval = intTime * 60 * 60 * 24 if intMeasure == "d":
elif intMeasure == 'h': intervalSec = intTime * 60 * 60 * 24
interval = intTime * 60 * 60 elif intMeasure == "h":
elif intMeasure == 'm': intervalSec = intTime * 60 * 60
interval = intTime * 60 elif intMeasure == "m":
else: intervalSec = intTime * 60
interval = intMeasure else:
else: intervalSec = intMeasure
parser.print_help() else:
parser.exit() parser.print_help()
parser.exit()
if (args.output_dir != None): if (args.output_dir != None):
outputDir = args.output_dir outputDir = args.output_dir
@@ -233,8 +240,8 @@ time.sleep(15)
#start traffic through cxs #start traffic through cxs
print("Starting CX Traffic") print("Starting CX Traffic")
for name in stations: for name in stations:
cmd = ("./lf_firemod.pl --mgr localhost --quiet 0 --action do_cmd --cmd \"set_cx_state default_tm " + name + " RUNNING\" >> sst.log") cmd = ("./lf_firemod.pl --mgr localhost --quiet 0 --action do_cmd --cmd \"set_cx_state default_tm " + name + " RUNNING\" >> sst.log")
execWrap(cmd) execWrap(cmd)
#create weblog for monitoring stations #create weblog for monitoring stations
@@ -260,6 +267,10 @@ h1, h2, h3 { text-align: center; font-family: "Century Gothic",Arial,Helvetica,s
</head> </head>
<body> <body>
<h1>Long test on %s</h1> <h1>Long test on %s</h1>
<p2>Key</p2>
<p1 style="background-color:rgb(0,255,0);">All stations associated and with ip</p1>
<p1 style="background-color:rgb(255,200,0);">All stations associated and at least one without ip</p1>
<p1 style="background-color:rgb(255,150,150);">No stations associated and without ip</p1>
<table> <table>
""" % datetime.date.today() """ % datetime.date.today()
@@ -277,8 +288,8 @@ f.write("</tr>\n")
print("Logging Info to {}".format(webLog)) print("Logging Info to {}".format(webLog))
timesLoop = math.ceil(durTime / intTime) timesLoop = math.ceil(durationSec / intervalSec)
#print("Looping {} times".format(timesLoop))
for min in range(timesLoop): for min in range(timesLoop):
f.write("<tr>\n") f.write("<tr>\n")
for radio, numStations in radios.items(): for radio, numStations in radios.items():
@@ -299,13 +310,14 @@ for min in range(timesLoop):
if withoutIP and not dissociated: if withoutIP and not dissociated:
f.write("<td style=\"background-color:rgb(255,200,0);\">{}/{}</td>\n".format(good,numStations)) #without IP assigned f.write("<td style=\"background-color:rgb(255,200,0);\">{}/{}</td>\n".format(good,numStations)) #without IP assigned
elif dissociated: elif dissociated:
f.write("<td style=\"background-color:rgb(255,0,0);\">{}/{}</td>\n".format(good,numStations)) #dissociated from AP f.write("<td style=\"background-color:rgb(255,150,150);\">{}/{}</td>\n".format(good,numStations)) #dissociated from AP
else: else:
f.write("<td style=\"background-color:rgb(0,255,0);\">{}/{}</td>\n".format(good,numStations)) #with IP and associated f.write("<td style=\"background-color:rgb(0,255,0);\">{}/{}</td>\n".format(good,numStations)) #with IP and associated
f.write("<td>{}</td>\n".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))) f.write("<td>{}</td>\n".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")))
f.write("</tr>\n") f.write("</tr>\n")
time.sleep(intTime) #Sleeps for specified interval in seconds #print("sleeping for {} seconds".format(intervalSec))
time.sleep(intervalSec) #Sleeps for specified interval in seconds
f.write("</table></body></html>\n") f.write("</table></body></html>\n")
@@ -314,8 +326,8 @@ f.close()
print("Stopping CX Traffic") print("Stopping CX Traffic")
for name in stations: for name in stations:
cmd = ("./lf_firemod.pl --mgr localhost --quiet 0 --action do_cmd --cmd \"set_cx_state default_tm " + name + " STOPPED\" >> sst.log") cmd = ("./lf_firemod.pl --mgr localhost --quiet 0 --action do_cmd --cmd \"set_cx_state default_tm " + name + " STOPPED\" >> sst.log")
execWrap(cmd) execWrap(cmd)
time.sleep(10) time.sleep(10)