From 4b7f7bba049c598976a45d905a5deaf42beddc34 Mon Sep 17 00:00:00 2001 From: estebanthilliez Date: Mon, 22 Apr 2024 20:45:36 +0200 Subject: [PATCH] Issue warning if using UUID URL scheme with create_slug --- borgmatic/hooks/healthchecks.py | 9 +++++++-- tests/unit/hooks/test_healthchecks.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/borgmatic/hooks/healthchecks.py b/borgmatic/hooks/healthchecks.py index 65afc02..f7daf67 100644 --- a/borgmatic/hooks/healthchecks.py +++ b/borgmatic/hooks/healthchecks.py @@ -66,8 +66,13 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev if healthchecks_state: ping_url = f'{ping_url}/{healthchecks_state}' - if hook_config.get('create_slug') and not ping_url_is_uuid: - ping_url = f'{ping_url}?create=1' + if hook_config.get('create_slug'): + if ping_url_is_uuid: + logger.warning( + f'{config_filename}: Healthchecks UUIDs do not support auto provisionning; ignoring' + ) + else: + ping_url = f'{ping_url}?create=1' logger.info(f'{config_filename}: Pinging Healthchecks {state.name.lower()}{dry_run_label}') logger.debug(f'{config_filename}: Using Healthchecks ping URL {ping_url}') diff --git a/tests/unit/hooks/test_healthchecks.py b/tests/unit/hooks/test_healthchecks.py index 74afe40..1e8a2a1 100644 --- a/tests/unit/hooks/test_healthchecks.py +++ b/tests/unit/hooks/test_healthchecks.py @@ -316,6 +316,20 @@ def test_ping_monitor_does_not_add_create_query_parameter_when_ping_url_is_uuid( ) +def test_ping_monitor_issues_warning_when_ping_url_is_uuid_and_create_slug_true(): + hook_config = {'ping_url': 'b3611b24-df9c-4d36-9203-fa292820bf2a', 'create_slug': True} + flexmock(module.logger).should_receive('warning').once() + + module.ping_monitor( + hook_config, + {}, + 'config.yaml', + state=module.monitor.State.FINISH, + monitoring_log_level=1, + dry_run=False, + ) + + def test_ping_monitor_with_connection_error_logs_warning(): flexmock(module.borgmatic.hooks.logs).should_receive('Forgetful_buffering_handler').never() hook_config = {'ping_url': 'https://example.com'}