Working commit. Output json from arke.py to file, read in gateway.py. gateway dumps out error file.

master
jowj 6 years ago
parent 29e959836f
commit 3590eaf4a5

@ -10,7 +10,6 @@ def monitor_AllTargets(monitoringtargets):
statuscode = requests.get(target).status_code
logger.info(f"target: {target} statuscode: {statuscode}")
responseTable[target] = statuscode
# prints the int of the status code. Find more at httpstatusrappers.com :)
except requests.ConnectionError:
logger.warn(f"target: {target} ERROR: Failure to connect.")
@ -18,12 +17,9 @@ def monitor_AllTargets(monitoringtargets):
return responseTable
target_Codes = monitor_AllTargets(arkevars.httpTargets)
currentdate = datetime.datetime.now().isoformat()
datastore = monitor_AllTargets(arkevars.httpTargets)
json_string = json.dumps(datastore)
# export shit as a dict
with open(f'{currentdate}.py','w') as file:
file.write("results = { \n")
for k in sorted (target_Codes.keys()):
file.write("'%s':'%s', \n" % (k, target_Codes[k]))
file.write("}\n")
file = open("results.json", "a+")
file.write(json_string)
file.write("\n")

@ -0,0 +1,20 @@
import json, datetime, os
"""
basically read a log file,
if what is being read contains a WARN:
Look at timestamp, target,
if more > 1 consecutive timestamp with the same target:
send to slack
"""
results = []
with open("results.json", "r") as json_File:
for line in json_File:
results.append(json.loads(line))
for key,value in results[-1].items():
if value != 200:
errorFile = open("errors.log", "w")
errorText = key + " is down." + "\n"
errorFile.write(errorText)
Loading…
Cancel
Save