Skip to content

Commit

Permalink
Fix a few remaining Pushover issues from the PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
witten committed Nov 19, 2024
1 parent 9807549 commit d09b4c7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 0 additions & 1 deletion borgmatic/config/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,6 @@ properties:
otherwise just the URL is shown.
example: Pushover Link
finish:
type: object
type: object
properties:
message:
Expand Down
9 changes: 5 additions & 4 deletions borgmatic/hooks/pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/monitor-your-backups.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 4 additions & 19 deletions tests/unit/hooks/test_pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit d09b4c7

Please sign in to comment.