Browse Source

incorporate feedback

Tom Janssen 1 week ago
parent
commit
7cca1358fb

+ 2 - 2
borgmatic/config/schema.yaml

@@ -3025,8 +3025,8 @@ properties:
             environment:
                 type: string
                 description: |
-                    Sentry monitor environment to specify. Used in the call
-                    to sentry of set.
+                    Sentry monitor environment used in the call to sentry. If not set,
+                    the Sentry default is used.
                 example: production
             states:
                 type: array

+ 2 - 3
borgmatic/hooks/monitoring/sentry.py

@@ -1,5 +1,6 @@
 import logging
 import re
+import urllib
 
 import requests
 
@@ -66,9 +67,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
     if dry_run:
         return
 
-    environment_query = ''
-    if environment:
-        environment_query = f'&environment={environment}'
+    environment_query = f'&environment={urllib.parse.quote(environment)}' if environment else ''
 
     logging.getLogger('urllib3').setLevel(logging.ERROR)
     try:

+ 2 - 2
docs/reference/configuration/monitoring/sentry.md

@@ -26,8 +26,8 @@ sentry:
 The `monitor_slug` value comes from the "Monitor Slug" under "Cron Details" on
 the same Sentry monitor page.
 
-The `environment` value is optionally specifies the enviroment that is used in
-sentry.
+The `environment` value optionally specifies the enviroment that is used in
+Sentry.
 
 With this configuration, borgmatic pings Sentry whenever borgmatic starts,
 finishes, or fails, but only when any of the `create`, `prune`, `compact`, or

+ 4 - 2
tests/unit/hooks/monitoring/test_sentry.py

@@ -13,14 +13,16 @@ from borgmatic.hooks.monitoring import sentry as module
             borgmatic.hooks.monitoring.monitor.State.START,
             ['start', 'finish', 'fail'],
             None,
-            'in_progress'
+            'in_progress',
         ),
         (borgmatic.hooks.monitoring.monitor.State.START, None, 'production', 'in_progress'),
         (borgmatic.hooks.monitoring.monitor.State.FINISH, ['finish'], 'development', 'ok'),
         (borgmatic.hooks.monitoring.monitor.State.FAIL, ['fail'], 'another-environment', 'error'),
     ),
 )
-def test_ping_monitor_constructs_cron_url_and_pings_it(state, configured_states, configured_environment, expected_status):
+def test_ping_monitor_constructs_cron_url_and_pings_it(
+    state, configured_states, configured_environment, expected_status
+):
     hook_config = {
         'data_source_name_url': 'https://5f80ec@o294220.ingest.us.sentry.io/203069',
         'monitor_slug': 'test',