Просмотр исходного кода

Fix a few remaining Pushover issues from the PR.

Dan Helfman 6 месяцев назад
Родитель
Сommit
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.
    file to support the new runtime and state directory logic.
  * #939: Fix borgmatic ignoring the "BORG_RELOCATED_REPO_ACCESS_IS_OK" and
  * #939: Fix borgmatic ignoring the "BORG_RELOCATED_REPO_ACCESS_IS_OK" and
    "BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK" environment variables.
    "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
 1.9.1
  * #928: Fix the user runtime directory location on macOS (and possibly Cygwin).
  * #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.
                             otherwise just the URL is shown.
                         example: Pushover Link
                         example: Pushover Link
             finish:
             finish:
-                type: object
                 type: object
                 type: object
                 properties:
                 properties:
                     message:
                     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 state_config.get('priority') == EMERGENCY_PRIORITY:
         if 'expire' not in state_config:
         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
             state_config['expire'] = 600
         if 'retry' not in state_config:
         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
             state_config['retry'] = 30
     else:
     else:
         if 'expire' in state_config or 'retry' in state_config:
         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 = {
     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(
     data = dict(
         {
         {
             'token': token,
             'token': token,
             'user': user,
             '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,
         **state_config,
     )
     )

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

@@ -338,7 +338,7 @@ pushover:
     fail:
     fail:
         message: "Backup <font color='#ff6961'>Failed</font>"
         message: "Backup <font color='#ff6961'>Failed</font>"
         priority: 2  # Requests acknowledgement for messages.
         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.
         retry: 30  # Used only for priority 2. Default is 30 seconds.
         device: "pixel8"
         device: "pixel8"
         title: "Backup Failed"
         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
     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
     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.logger).should_receive('warning').never()
     flexmock(module.requests).should_receive('post').never()
     flexmock(module.requests).should_receive('post').never()
+
     with pytest.raises(ValueError):
     with pytest.raises(ValueError):
         module.ping_monitor(
         module.ping_monitor(
             hook_config,
             hook_config,
@@ -452,15 +453,7 @@ def test_ping_monitor_config_with_minimum_config_fail_state_backup_successfully_
     '''
     '''
     hook_config = {'token': 'ksdjfwoweijfvwoeifvjmwghagy92', 'user': '983hfe0of902lkjfa2amanfgui'}
     hook_config = {'token': 'ksdjfwoweijfvwoeifvjmwghagy92', 'user': '983hfe0of902lkjfa2amanfgui'}
     flexmock(module.logger).should_receive('warning').never()
     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(
     module.ping_monitor(
         hook_config,
         hook_config,
@@ -481,15 +474,7 @@ def test_ping_monitor_config_incorrect_state_exit_early():
         'user': '983hfe0of902lkjfa2amanfgui',
         'user': '983hfe0of902lkjfa2amanfgui',
     }
     }
     flexmock(module.logger).should_receive('warning').never()
     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(
     module.ping_monitor(
         hook_config,
         hook_config,