From 51a695ed9eaa2c8518039aca0adfa1f69010ac06 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 7 May 2024 10:53:44 +0200 Subject: [PATCH] Don't fail on problems with downtime for db either --- templates/script/restart-db-cluster.erb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/templates/script/restart-db-cluster.erb b/templates/script/restart-db-cluster.erb index 6ea18ba..418512c 100755 --- a/templates/script/restart-db-cluster.erb +++ b/templates/script/restart-db-cluster.erb @@ -30,7 +30,10 @@ def add_downtime(fqdn: str, post_url = 'https://{}/thruk/r/hosts/{}/cmd/{}'.format( monitor_host, fqdn, action) headers = {'X-Thruk-Auth-Key': apikey} - requests.post(post_url, data=data, headers=headers) + try: + requests.post(post_url, data=data, headers=headers) + except Exception: + print("Failed to add downtime for {}".format(fqdn)) def remove_downtime(fqdn: str, @@ -42,12 +45,15 @@ def remove_downtime(fqdn: str, get_url = 'https://{}/thruk/r/hosts?name={}&columns=services'.format( monitor_host, fqdn) headers = {'X-Thruk-Auth-Key': apikey} - req = requests.get(get_url, headers=headers) - action = 'del_active_service_downtimes' - for service in req.json()[0]['services']: - post_url = 'https://{}/thruk/r/services/{}/{}/cmd/{}'.format( - monitor_host, fqdn, urllib.parse.quote(service), action) - requests.post(post_url, headers=headers) + try: + req = requests.get(get_url, headers=headers) + action = 'del_active_service_downtimes' + for service in req.json()[0]['services']: + post_url = 'https://{}/thruk/r/services/{}/{}/cmd/{}'.format( + monitor_host, fqdn, urllib.parse.quote(service), action) + requests.post(post_url, headers=headers) + except Exception: + print("Failed to remove downtime for {}".format(fqdn)) def main() -> int: