浏览代码

Fix a few remaining Pushover issues from the PR.

Dan Helfman 6 月之前
父节点
当前提交
d09b4c72a9
共有 5 个文件被更改,包括 12 次插入25 次删除
  1. 2 0
      NEWS
  2. 0 1
      borgmatic/config/schema.yaml
  3. 5 4
      borgmatic/hooks/pushover.py
  4. 1 1
      docs/how-to/monitor-your-backups.md
  5. 4 19
      tests/unit/hooks/test_pushover.py

+ 2 - 0
NEWS

@@ -11,6 +11,8 @@
    file to support the new runtime and state directory logic.
  * #939: Fix borgmatic ignoring the "BORG_RELOCATED_REPO_ACCESS_IS_OK" and
    "BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK" environment variables.
+ * Add a Pushover monitoring hook. See the documentation for more information:
+   https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#pushover-hook
 
 1.9.1
  * #928: Fix the user runtime directory location on macOS (and possibly Cygwin).

+ 0 - 1
borgmatic/config/schema.yaml

@@ -1719,7 +1719,6 @@ properties:
                             otherwise just the URL is shown.
                         example: Pushover Link
             finish:
-                type: object
                 type: object
                 properties:
                     message:

+ 5 - 4
borgmatic/hooks/pushover.py

@@ -39,10 +39,10 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
 
     if state_config.get('priority') == EMERGENCY_PRIORITY:
         if 'expire' not in state_config:
-            logger.info(f'{config_filename}: Setting expire to default (10min).')
+            logger.info(f'{config_filename}: Setting expire to default (10 min).')
             state_config['expire'] = 600
         if 'retry' not in state_config:
-            logger.info(f'{config_filename}: Setting retry to default (30sec).')
+            logger.info(f'{config_filename}: Setting retry to default (30 sec).')
             state_config['retry'] = 30
     else:
         if 'expire' in state_config or 'retry' in state_config:
@@ -51,14 +51,15 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
             )
 
     state_config = {
-        key: (int(value) if key in 'html' else value) for key, value in state_config.items()
+        key: (int(value) if key == 'html' else value) for key, value in state_config.items()
     }
 
     data = dict(
         {
             'token': token,
             'user': user,
-            'message': state.name.lower(),  # default to state name. Can be overwritten in state_config loop below.
+            # Default to state name. Can be overwritten by state_config below.
+            'message': state.name.lower(),
         },
         **state_config,
     )

+ 1 - 1
docs/how-to/monitor-your-backups.md

@@ -338,7 +338,7 @@ pushover:
     fail:
         message: "Backup <font color='#ff6961'>Failed</font>"
         priority: 2  # Requests acknowledgement for messages.
-        expire: 1200  # Used only for priority 2. Default is 1200 seconds.
+        expire: 600  # Used only for priority 2. Default is 600 seconds.
         retry: 30  # Used only for priority 2. Default is 30 seconds.
         device: "pixel8"
         title: "Backup Failed"

+ 4 - 19
tests/unit/hooks/test_pushover.py

@@ -222,7 +222,7 @@ def test_ping_monitor_start_state_backup_default_message_with_priority_emergency
     )
 
 
-def test_ping_monitor_start_state_backup_default_message_with_priority_high_declared_expire_and_retry_ignored_success():
+def test_ping_monitor_start_state_backup_default_message_with_priority_high_declared_expire_and_retry_raises():
     '''
     This simulates priority level 1, retry and expiry being set. Since expire
     and retry are only used for priority level 2, they should not be included
@@ -238,6 +238,7 @@ def test_ping_monitor_start_state_backup_default_message_with_priority_high_decl
 
     flexmock(module.logger).should_receive('warning').never()
     flexmock(module.requests).should_receive('post').never()
+
     with pytest.raises(ValueError):
         module.ping_monitor(
             hook_config,
@@ -452,15 +453,7 @@ def test_ping_monitor_config_with_minimum_config_fail_state_backup_successfully_
     '''
     hook_config = {'token': 'ksdjfwoweijfvwoeifvjmwghagy92', 'user': '983hfe0of902lkjfa2amanfgui'}
     flexmock(module.logger).should_receive('warning').never()
-    flexmock(module.requests).should_receive('post').with_args(
-        'https://api.pushover.net/1/messages.json',
-        headers={'Content-type': 'application/x-www-form-urlencoded'},
-        data={
-            'token': 'ksdjfwoweijfvwoeifvjmwghagy92',
-            'user': '983hfe0of902lkjfa2amanfgui',
-            'message': 'fail',
-        },
-    ).and_return(flexmock(ok=True)).never()
+    flexmock(module.requests).should_receive('post').and_return(flexmock(ok=True)).never()
 
     module.ping_monitor(
         hook_config,
@@ -481,15 +474,7 @@ def test_ping_monitor_config_incorrect_state_exit_early():
         'user': '983hfe0of902lkjfa2amanfgui',
     }
     flexmock(module.logger).should_receive('warning').never()
-    flexmock(module.requests).should_receive('post').with_args(
-        'https://api.pushover.net/1/messages.json',
-        headers={'Content-type': 'application/x-www-form-urlencoded'},
-        data={
-            'token': 'ksdjfwoweijfvwoeifvjmwghagy92',
-            'user': '983hfe0of902lkjfa2amanfgui',
-            'message': 'start',
-        },
-    ).and_return(flexmock(ok=True)).never()
+    flexmock(module.requests).should_receive('post').and_return(flexmock(ok=True)).never()
 
     module.ping_monitor(
         hook_config,