forked from borgmatic-collective/borgmatic
Compare commits
3 Commits
2e4c0cc7e7
...
407bb33359
Author | SHA1 | Date |
---|---|---|
estebanthilliez | 407bb33359 | |
estebanthilliez | 4b7f7bba04 | |
estebanthilliez | cfdc0a1f2a |
|
@ -1667,7 +1667,8 @@ properties:
|
|||
description: |
|
||||
Create the check if it does not exist. Only works with
|
||||
the slug URL scheme (https://hc-ping.com/<ping-key>/<slug>
|
||||
as opposed to https://hc-ping.com/<uuid>). Defaults to false.
|
||||
as opposed to https://hc-ping.com/<uuid>).
|
||||
Defaults to false.
|
||||
example: true
|
||||
description: |
|
||||
Configuration for a monitoring integration with Healthchecks. Create
|
||||
|
|
|
@ -60,14 +60,19 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
|
|||
)
|
||||
return
|
||||
|
||||
ping_url_is_uuid = re.match(r'(\w{4}-?){4}$', hook_config['ping_url'])
|
||||
ping_url_is_uuid = re.search(r'\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$', ping_url)
|
||||
|
||||
healthchecks_state = MONITOR_STATE_TO_HEALTHCHECKS.get(state)
|
||||
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}')
|
||||
|
|
|
@ -299,7 +299,7 @@ def test_ping_monitor_does_not_add_create_query_parameter_when_create_slug_false
|
|||
|
||||
|
||||
def test_ping_monitor_does_not_add_create_query_parameter_when_ping_url_is_uuid():
|
||||
hook_config = {'ping_url': 'abcd-efgh-ijkl-mnop', 'create_slug': True}
|
||||
hook_config = {'ping_url': 'b3611b24-df9c-4d36-9203-fa292820bf2a', 'create_slug': True}
|
||||
flexmock(module.requests).should_receive('post').with_args(
|
||||
f"https://hc-ping.com/{hook_config['ping_url']}",
|
||||
data=''.encode('utf-8'),
|
||||
|
@ -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'}
|
||||
|
|
Loading…
Reference in New Issue