From 8b179e46474882c50dc2ad4458cd1a5addab9a53 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 24 May 2022 14:09:42 -0700 Subject: [PATCH] Reverse logic of Healtchecks "skip_states" option to just "states" (#525). --- NEWS | 4 ++-- borgmatic/config/schema.yaml | 8 ++++---- borgmatic/hooks/healthchecks.py | 4 ++-- tests/unit/hooks/test_healthchecks.py | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index d02997b0..9de69c6c 100644 --- a/NEWS +++ b/NEWS @@ -3,8 +3,8 @@ logs to send to the Healthchecks server. * #402: Remove the error when "archive_name_format" is specified but a retention prefix isn't. * #420: Warn when an unsupported variable is used in a hook command. - * #525: Add Healthchecks monitoring hook "skip_states" option to disable pinging for particular - monitoring states. + * #525: Add Healthchecks monitoring hook "states" option to only enable pinging for particular + monitoring states (start, finish, fail). * #528: Improve the error message when a configuration override contains an invalid value. * #531: BREAKING: When deep merging common configuration, merge colliding list values by appending them. Previously, one list replaced the other. diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 35cb38e1..c4b802af 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -901,7 +901,7 @@ properties: send all logs and disable this truncation. Defaults to 100000. example: 200000 - skip_states: + states: type: array items: type: string @@ -911,9 +911,9 @@ properties: - fail uniqueItems: true description: | - List of one or more monitoring states to skip - pinging for: "start", "finish", and/or "fail". - Defaults to pinging for all states. + List of one or more monitoring states to ping for: + "start", "finish", and/or "fail". Defaults to + pinging for all states. description: | Configuration for a monitoring integration with Healthchecks. Create an account at https://healthchecks.io diff --git a/borgmatic/hooks/healthchecks.py b/borgmatic/hooks/healthchecks.py index 7b562615..055cfaf0 100644 --- a/borgmatic/hooks/healthchecks.py +++ b/borgmatic/hooks/healthchecks.py @@ -98,9 +98,9 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_ ) dry_run_label = ' (dry run; not actually pinging)' if dry_run else '' - if state.name.lower() in hook_config.get('skip_states', []): + if 'states' in hook_config and state.name.lower() not in hook_config['states']: logger.info( - f'{config_filename}: Skipping Healthchecks {state.name.lower()} ping due to configured skip states' + f'{config_filename}: Skipping Healthchecks {state.name.lower()} ping due to configured states' ) return diff --git a/tests/unit/hooks/test_healthchecks.py b/tests/unit/hooks/test_healthchecks.py index 3a626cc5..eaac9ff5 100644 --- a/tests/unit/hooks/test_healthchecks.py +++ b/tests/unit/hooks/test_healthchecks.py @@ -187,9 +187,9 @@ def test_ping_monitor_dry_run_does_not_hit_ping_url(): ) -def test_ping_monitor_with_skip_states_does_not_hit_ping_url(): +def test_ping_monitor_does_not_hit_ping_url_when_states_not_matching(): flexmock(module).should_receive('Forgetful_buffering_handler') - hook_config = {'ping_url': 'https://example.com', 'skip_states': ['start']} + hook_config = {'ping_url': 'https://example.com', 'states': ['finish']} flexmock(module.requests).should_receive('post').never() module.ping_monitor( @@ -201,9 +201,9 @@ def test_ping_monitor_with_skip_states_does_not_hit_ping_url(): ) -def test_ping_monitor_hits_ping_url_with_non_matching_skip_states(): +def test_ping_monitor_hits_ping_url_when_states_matching(): flexmock(module).should_receive('Forgetful_buffering_handler') - hook_config = {'ping_url': 'https://example.com', 'skip_states': ['finish']} + hook_config = {'ping_url': 'https://example.com', 'states': ['start', 'finish']} flexmock(module.requests).should_receive('post').with_args( 'https://example.com/start', data=''.encode('utf-8') )