Move to alert_file var; fix json parsing error from last commit.

master
jowj 4 years ago
parent 71a2df01f8
commit 97b222491a

@ -14,8 +14,9 @@ logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%Y/%m/%d %I:%M:%S
logger = logging.getLogger("arke") logger = logging.getLogger("arke")
last_round_file = "/shared/state.log" last_round_file = "/shared/state.json"
this_round_file = "/shared/results.json" this_round_file = "/shared/results.json"
alert_file = "/shared/alerts.log"
def monitor_HttpTargets(monitoringtargets): def monitor_HttpTargets(monitoringtargets):
@ -75,7 +76,7 @@ while is_on:
today = datetime.today() today = datetime.today()
datastore = {} datastore = {}
# make sure http targets are /up/ # make sure http targets are /up/
datastore['http'] = monitor_HttpTargets(arkevars.httpTargets) datastore['http'] = monitor_HttpTargets(arkevars.httpTargets)
@ -110,16 +111,13 @@ while is_on:
# queue up an alert if stateChanged = True # queue up an alert if stateChanged = True
results = [] results = []
with open(this_round_file, "r+", encoding="utf-8") as json_File: with open(this_round_file, "r+", encoding="utf-8") as json_File:
pdb.set_trace()
json_data = json.load(json_File) json_data = json.load(json_File)
for item in json_data: for key, value in json_data.items():
results.append(item) for key, value in value.items():
for item in results: if stateChanged is True:
for key, value in item.items(): errorFile = open(alert_file, "a+")
if stateChanged is True: errorText = str(key) + " " + str(value) + "\n"
errorFile = open("/shared/alerts.log", "a+") errorFile.write(errorText)
errorText = key + " returned with status " + str(value) + "\n"
errorFile.write(errorText)
# Copy current results to state.log file for next iteration # Copy current results to state.log file for next iteration
with open(last_round_file, "a+") as json_File: with open(last_round_file, "a+") as json_File:

Loading…
Cancel
Save