浏览代码

Reverse logic of Healtchecks "skip_states" option to just "states" (#525).

Dan Helfman 3 年之前
父节点
当前提交
8b179e4647
共有 4 个文件被更改,包括 12 次插入12 次删除
  1. 2 2
      NEWS
  2. 4 4
      borgmatic/config/schema.yaml
  3. 2 2
      borgmatic/hooks/healthchecks.py
  4. 4 4
      tests/unit/hooks/test_healthchecks.py

+ 2 - 2
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.

+ 4 - 4
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

+ 2 - 2
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
 

+ 4 - 4
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')
     )