diff --git a/NEWS b/NEWS index 281b0d6f..68f7ec31 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ just skipping the Borg call. * #1242: Fix a regression in which the "spot" check hung while collecting archive contents. * #1245: Fix a regression in which the KeePassXC credential hook password prompt was invisible. + * #1246: Fix a regression in which the ntfy monitoring hook failed to send a ping when the + "priority" option was set. 2.1.0 * TL;DR: Many logging, memory, and performance improvements. Mind those breaking changes! diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index b389db8b..e29c1e58 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -2342,6 +2342,13 @@ properties: example: Your backups have started. priority: type: string + enum: + - max + - urgent + - high + - default + - low + - min description: | The priority to set. example: min @@ -2366,6 +2373,13 @@ properties: example: Your backups have finished. priority: type: string + enum: + - max + - urgent + - high + - default + - low + - min description: | The priority to set. example: min @@ -2390,6 +2404,13 @@ properties: example: Your backups have failed. priority: type: string + enum: + - max + - urgent + - high + - default + - low + - min description: | The priority to set. example: max diff --git a/borgmatic/hooks/monitoring/ntfy.py b/borgmatic/hooks/monitoring/ntfy.py index 1c42cf0c..0429e703 100644 --- a/borgmatic/hooks/monitoring/ntfy.py +++ b/borgmatic/hooks/monitoring/ntfy.py @@ -22,6 +22,16 @@ def initialize_monitor( ''' +PRIORITY_NAME_TO_ID = { + 'max': 5, + 'urgent': 5, + 'high': 4, + 'default': 3, + 'low': 2, + 'min': 1, +} + + def ping_monitor(hook_config, config, config_filename, state, monitoring_log_level, dry_run): ''' Ping the configured Ntfy topic. Use the given configuration filename in any log entries. @@ -31,13 +41,13 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev if state.name.lower() in run_states: dry_run_label = ' (dry run; not actually pinging)' if dry_run else '' - + default_priority = PRIORITY_NAME_TO_ID['default'] state_config = hook_config.get( state.name.lower(), { 'title': f'A borgmatic {state.name} event happened', 'message': f'A borgmatic {state.name} event happened', - 'priority': 'default', + 'priority': default_priority, 'tags': 'borgmatic', }, ) @@ -55,7 +65,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev 'topic': topic, 'title': state_config.get('title'), 'message': state_config.get('message'), - 'priority': state_config.get('priority'), + 'priority': PRIORITY_NAME_TO_ID.get(state_config.get('priority'), default_priority), 'tags': state_config.get('tags'), } diff --git a/tests/unit/hooks/monitoring/test_ntfy.py b/tests/unit/hooks/monitoring/test_ntfy.py index 39a419f5..7588edd6 100644 --- a/tests/unit/hooks/monitoring/test_ntfy.py +++ b/tests/unit/hooks/monitoring/test_ntfy.py @@ -24,7 +24,7 @@ CUSTOM_MESSAGE_PAYLOAD = { 'topic': TOPIC, 'title': CUSTOM_MESSAGE_CONFIG['title'], 'message': CUSTOM_MESSAGE_CONFIG['message'], - 'priority': CUSTOM_MESSAGE_CONFIG['priority'], + 'priority': 1, 'tags': CUSTOM_MESSAGE_CONFIG['tags'], } @@ -34,7 +34,7 @@ def default_message_payload(state=Enum): 'topic': TOPIC, 'title': f'A borgmatic {state.name} event happened', 'message': f'A borgmatic {state.name} event happened', - 'priority': 'default', + 'priority': 3, 'tags': 'borgmatic', }