From bf7b163ccd4484a93b3dd1d8551314e0ff84a7d8 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Mon, 24 Jun 2024 10:25:08 +0100 Subject: [PATCH] added early out for dry run --- borgmatic/hooks/uptimekuma.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/borgmatic/hooks/uptimekuma.py b/borgmatic/hooks/uptimekuma.py index 59f20df..8b3e6e6 100644 --- a/borgmatic/hooks/uptimekuma.py +++ b/borgmatic/hooks/uptimekuma.py @@ -27,22 +27,21 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev status = 'down' if state.name.lower() == 'fail' else 'up' push_url = hook_config.get('push_url', 'https://example.uptime.kuma/api/push/abcd1234') query = f'status={status}&msg={state.name.lower()}' - logger.info(f'{config_filename}: Pinging Uptime Kuma push_url {push_url}?{query} {dry_run_label}') logger.debug( f'{config_filename}: Full Uptime Kuma state URL {push_url}?{query}' ) - - if not dry_run: - logging.getLogger('urllib3').setLevel(logging.ERROR) - try: - response = requests.get( - f'{push_url}?{query}' - ) - if not response.ok: - response.raise_for_status() - except requests.exceptions.RequestException as error: - logger.warning(f'{config_filename}: Uptime Kuma error: {error}') + if dry_run: + return + logging.getLogger('urllib3').setLevel(logging.ERROR) + try: + response = requests.get( + f'{push_url}?{query}' + ) + if not response.ok: + response.raise_for_status() + except requests.exceptions.RequestException as error: + logger.warning(f'{config_filename}: Uptime Kuma error: {error}') def destroy_monitor( ping_url_or_uuid, config, config_filename, monitoring_log_level, dry_run