Move from magic strings to two variables.

master
jowj 4 years ago
parent 34e94f6576
commit 50df968293

@ -13,6 +13,10 @@ logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%Y/%m/%d %I:%M:%S
logger = logging.getLogger("arke")
last_round_file = "/shared/state.log"
this_round_file = "/shared/results.json"
def monitor_HttpTargets(monitoringtargets):
responseTable = {}
for target in monitoringtargets:
@ -83,18 +87,18 @@ while is_on:
domain_json = json.dumps(domain_info)
# write new results to file
file = open("/shared/results.json", "a+")
file = open(this_round_file, "a+")
file.write(json_string)
file.write(cert_json)
file.write(domain_json)
file.close()
# track state
file = open("/shared/results.json", "r")
if os.path.exists("/shared/state.log"):
stateFile = open("/shared/state.log", "r")
file = open(this_round_file, "r")
if os.path.exists(last_round_file):
stateFile = open(last_round_file, "r")
else:
stateFile = open("/shared/state.log", "w+")
stateFile = open(last_round_file, "w+")
oldData = stateFile.read()
if oldData != file.read():
@ -103,11 +107,11 @@ while is_on:
stateChanged = False
# delete state.log so I can write to it cleanly
os.remove("/shared/state.log")
os.remove(last_round_file)
# queue up an alert if stateChanged = True
results = []
with open("/shared/results.json", "r") as json_File:
with open(this_round_file, "r") as json_File:
json_data = json.load(json_File)
for item in json_data:
results.append(item)
@ -119,10 +123,10 @@ while is_on:
errorFile.write(errorText)
# Copy current results to state.log file for next iteration
errorFile = open("/shared/state.log", "a+")
errorFile = open(last_round_file, "a+")
errorFile.write(json_string)
errorFile.write(cert_json)
errorFile.write(domain_json)
errorFile.close()
os.remove("/shared/results.json")
os.remove(this_round_file)
time.sleep(60)

Loading…
Cancel
Save