add-healthcheck-support #17

Merged
jblu merged 2 commits from add-healthcheck-support into main 2023-06-05 23:18:25 -05:00
3 changed files with 22 additions and 15 deletions

View File

@ -10,20 +10,17 @@ def apprise_notify(req_obj, host, port, aurls, title, body):
class AppriseClient: class AppriseClient:
def __init__(self): def __init__(self):
self.config = '' if os.getenv("DOCKER"):
try: self.host = os.getenv("host")
if os.environ["DOCKER"]: self.port = os.getenv("port")
self.host = os.environ["host"] self.aurls = os.getenv("aurls")
self.port = os.environ["port"] self.title = os.getenv("title")
self.aurls = os.environ["aurls"] self.body = os.getenv("body")
self.title = os.environ["title"] if os.getenv("toml_path"):
self.body = os.environ["body"] config_file_path=os.getenv("toml_path")
if os.environ["toml_path"]:
config_file_path=os.environ["toml_path"]
with open(config_file_path, 'rb') as c: with open(config_file_path, 'rb') as c:
self.config = load(c) self.config = load(c)
except:
KeyError
if os.path.exists('./config.toml'): if os.path.exists('./config.toml'):
config_file_path = './config.toml' config_file_path = './config.toml'
with open(config_file_path, 'rb') as c: with open(config_file_path, 'rb') as c:

View File

@ -42,3 +42,9 @@ def get_script_runtime(self):
self.extm = f"Execution time: [{elapsed_time}]" self.extm = f"Execution time: [{elapsed_time}]"
if self.use_apprise: if self.use_apprise:
self.extm = f"Execution time: [{elapsed_time}]" self.extm = f"Execution time: [{elapsed_time}]"
def send_ping(self, req_obj, healthcheck_url):
try:
req_obj.get(healthcheck_url, timeout=10)
except req_obj.RequestException as e:
self.tl.info(f"Ping failed: {e}")

View File

@ -54,6 +54,8 @@ class Crn:
#containers #containers
self.observed_containers = list(self.config["containers"].values()) self.observed_containers = list(self.config["containers"].values())
self.container_statuses = ["paused","dead","created","exited","removing","restarting","created"] self.container_statuses = ["paused","dead","created","exited","removing","restarting","created"]
#healthcheck
self.healthcheck_url = self.config["healthcheck"]["healthcheck_url"]
cont_log(self) cont_log(self)
cont_notify(self) cont_notify(self)
@ -80,6 +82,8 @@ class Crn:
cont_notify_summary(self, apprise_notify, requests) cont_notify_summary(self, apprise_notify, requests)
if self.use_apprise: if self.use_apprise:
cont_notify_summary(self, apprise_notify, requests) cont_notify_summary(self, apprise_notify, requests)
send_ping(self, requests, self.healthcheck_url)
# Run # Run
if __name__== "__main__": if __name__== "__main__":
Crn() Crn()