From 50df9682939e6c482c9c0f7148d3781813f706d3 Mon Sep 17 00:00:00 2001 From: jowj Date: Mon, 27 Jan 2020 16:45:47 -0600 Subject: [PATCH] Move from magic strings to two variables. --- arke.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/arke.py b/arke.py index a819f59..0fbc5a1 100644 --- a/arke.py +++ b/arke.py @@ -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)