From 97b222491a0ba479645882bc24ae8b2dccb28c1d Mon Sep 17 00:00:00 2001 From: jowj Date: Tue, 28 Jan 2020 16:05:22 -0600 Subject: [PATCH] Move to alert_file var; fix json parsing error from last commit. --- arke.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/arke.py b/arke.py index 762ea9d..a62420b 100644 --- a/arke.py +++ b/arke.py @@ -14,8 +14,9 @@ logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%Y/%m/%d %I:%M:%S logger = logging.getLogger("arke") -last_round_file = "/shared/state.log" +last_round_file = "/shared/state.json" this_round_file = "/shared/results.json" +alert_file = "/shared/alerts.log" def monitor_HttpTargets(monitoringtargets): @@ -75,7 +76,7 @@ while is_on: today = datetime.today() datastore = {} - + # make sure http targets are /up/ datastore['http'] = monitor_HttpTargets(arkevars.httpTargets) @@ -110,16 +111,13 @@ while is_on: # queue up an alert if stateChanged = True results = [] with open(this_round_file, "r+", encoding="utf-8") as json_File: - pdb.set_trace() json_data = json.load(json_File) - for item in json_data: - results.append(item) - for item in results: - for key, value in item.items(): - if stateChanged is True: - errorFile = open("/shared/alerts.log", "a+") - errorText = key + " returned with status " + str(value) + "\n" - errorFile.write(errorText) + for key, value in json_data.items(): + for key, value in value.items(): + if stateChanged is True: + errorFile = open(alert_file, "a+") + errorText = str(key) + " " + str(value) + "\n" + errorFile.write(errorText) # Copy current results to state.log file for next iteration with open(last_round_file, "a+") as json_File: