Require statechange trigger to write to alerts.log

master
jowj 6 years ago
parent c5fbfbaa91
commit b1d54b3bcc

@ -26,9 +26,9 @@ while is_on:
file = open("/shared/results.json", "r") file = open("/shared/results.json", "r")
oldData = file.read() oldData = file.read()
if oldData == json_string: if oldData == json_string:
state = False stateChanged = False
else: else:
state = True stateChanged = True
# old file removal must happen after state tracking: # old file removal must happen after state tracking:
os.remove("/shared/results.json") os.remove("/shared/results.json")
@ -45,11 +45,10 @@ while is_on:
results.append(json.loads(line)) results.append(json.loads(line))
for key,value in results[-1].items(): for key,value in results[-1].items():
if value != 200: if stateChanged == True:
if state == True: errorFile = open("/shared/alerts.log", "w")
errorFile = open("/shared/alerts.log", "w") errorText = key + " is down." + "\n"
errorText = key + " is down." + "\n" errorFile.write(errorText)
errorFile.write(errorText) errorFile.close()
errorFile.close()
time.sleep(60) time.sleep(60)

Loading…
Cancel
Save