From 85092690852cdea03f22b0b62e0fa0bdfbf05f2d Mon Sep 17 00:00:00 2001 From: jblu Date: Mon, 5 Jun 2023 23:10:33 -0500 Subject: [PATCH 1/2] #14 --- AppriseClient.py | 2 +- clogging.py | 8 +++++++- crane.py | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AppriseClient.py b/AppriseClient.py index f4d821f..c6f4aa9 100644 --- a/AppriseClient.py +++ b/AppriseClient.py @@ -12,7 +12,7 @@ class AppriseClient: def __init__(self): self.config = '' try: - if os.environ["DOCKER"]: + if os.get["DOCKER"]: self.host = os.environ["host"] self.port = os.environ["port"] self.aurls = os.environ["aurls"] diff --git a/clogging.py b/clogging.py index a1167ce..aa7f7e1 100644 --- a/clogging.py +++ b/clogging.py @@ -41,4 +41,10 @@ def get_script_runtime(self): if self.use_pushover: self.extm = f"Execution time: [{elapsed_time}]" if self.use_apprise: - self.extm = f"Execution time: [{elapsed_time}]" \ No newline at end of file + 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}") \ No newline at end of file diff --git a/crane.py b/crane.py index dbedac2..9c018cb 100644 --- a/crane.py +++ b/crane.py @@ -54,6 +54,8 @@ class Crn: #containers self.observed_containers = list(self.config["containers"].values()) self.container_statuses = ["paused","dead","created","exited","removing","restarting","created"] + #healthcheck + self.healthcheck_url = self.config["healthcheck"]["healthcheck_url"] cont_log(self) cont_notify(self) @@ -80,6 +82,8 @@ class Crn: cont_notify_summary(self, apprise_notify, requests) if self.use_apprise: cont_notify_summary(self, apprise_notify, requests) + send_ping(self, requests, self.healthcheck_url) + # Run if __name__== "__main__": Crn() \ No newline at end of file -- 2.45.2 From 43c79b13cac4742fdd7101d45f1a507cfdd00636 Mon Sep 17 00:00:00 2001 From: jblu Date: Mon, 5 Jun 2023 23:16:19 -0500 Subject: [PATCH 2/2] changed apprise client --- AppriseClient.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/AppriseClient.py b/AppriseClient.py index c6f4aa9..f8a8992 100644 --- a/AppriseClient.py +++ b/AppriseClient.py @@ -10,20 +10,17 @@ def apprise_notify(req_obj, host, port, aurls, title, body): class AppriseClient: def __init__(self): - self.config = '' - try: - if os.get["DOCKER"]: - self.host = os.environ["host"] - self.port = os.environ["port"] - self.aurls = os.environ["aurls"] - self.title = os.environ["title"] - self.body = os.environ["body"] - if os.environ["toml_path"]: - config_file_path=os.environ["toml_path"] - with open(config_file_path, 'rb') as c: - self.config = load(c) - except: - KeyError + if os.getenv("DOCKER"): + self.host = os.getenv("host") + self.port = os.getenv("port") + self.aurls = os.getenv("aurls") + self.title = os.getenv("title") + self.body = os.getenv("body") + if os.getenv("toml_path"): + config_file_path=os.getenv("toml_path") + with open(config_file_path, 'rb') as c: + self.config = load(c) + if os.path.exists('./config.toml'): config_file_path = './config.toml' with open(config_file_path, 'rb') as c: -- 2.45.2