|
|
|
@ -1,8 +1,14 @@
|
|
|
|
|
import requests, arkevars, json, logging, datetime, os, time
|
|
|
|
|
import requests
|
|
|
|
|
import arkevars
|
|
|
|
|
import json
|
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%Y/%m/%d %I:%M:%S %p',level=logging.INFO,filename='arke.log')
|
|
|
|
|
logger = logging.getLogger("arke")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def monitor_AllTargets(monitoringtargets):
|
|
|
|
|
responseTable = {}
|
|
|
|
|
for target in monitoringtargets:
|
|
|
|
@ -14,10 +20,12 @@ def monitor_AllTargets(monitoringtargets):
|
|
|
|
|
except requests.ConnectionError:
|
|
|
|
|
logger.warn(f"target: {target} ERROR: Failure to connect.")
|
|
|
|
|
responseTable[target] = "Failed to connect."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return responseTable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_on = True
|
|
|
|
|
|
|
|
|
|
while is_on:
|
|
|
|
|
datastore = monitor_AllTargets(arkevars.httpTargets)
|
|
|
|
|
json_string = json.dumps(datastore)
|
|
|
|
@ -27,7 +35,7 @@ while is_on:
|
|
|
|
|
file.write(json_string)
|
|
|
|
|
file.write("\n")
|
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# track state
|
|
|
|
|
file = open("/shared/results.json", "r")
|
|
|
|
|
stateFile = open("/shared/state.log", "r")
|
|
|
|
@ -47,10 +55,10 @@ while is_on:
|
|
|
|
|
for line in json_File:
|
|
|
|
|
results.append(json.loads(line))
|
|
|
|
|
for item in results:
|
|
|
|
|
for key,value in item.items():
|
|
|
|
|
if stateChanged == True:
|
|
|
|
|
for key, value in item.items():
|
|
|
|
|
if stateChanged is True:
|
|
|
|
|
errorFile = open("/shared/alerts.log", "a+")
|
|
|
|
|
errorText = key + " returned with status " + str(value) + "\n"
|
|
|
|
|
errorText = key + " returned with status " + str(value) + "\n"
|
|
|
|
|
errorFile.write(errorText)
|
|
|
|
|
|
|
|
|
|
# track state
|
|
|
|
@ -61,4 +69,3 @@ while is_on:
|
|
|
|
|
errorFile.close()
|
|
|
|
|
os.remove("/shared/results.json")
|
|
|
|
|
time.sleep(60)
|
|
|
|
|
|
|
|
|
|