grafana/pkg/services/ngalert/sender
Matthew Jacobson 940d18ad57
Alerting: Sanitize invalid label/annotation names for external alertmanagers (#54537)
* Alerting: Sanitize invalid label/annotation names for external alertmanagers

Grafana's built-in Alertmanager supports both Unicode label keys and values; however, if using an external
Prometheus Alertmanager label keys must be compatible with their data model.
This means label keys must only contain ASCII letters, numbers, as well as underscores and match the regex
`[a-zA-Z_][a-zA-Z0-9_]*`.

Any invalid characters will now be removed or replaced by the Grafana alerting engine before being sent to
the external Alertmanager according to the following rules:

- `Whitespace` will be removed.
- `ASCII characters` will be replaced with `_`.
- `All other characters` will be replaced with their lower-case hex representation.

* Prefix hex replacements with `0x`

* Refactor for clarity

* Apply suggestions from code review

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>

Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
2022-09-07 11:39:39 -04:00
..
router_test.go Alerting: Configure alert manager data source as an external AM (#52081) 2022-08-01 10:20:43 +02:00
router.go Alerting: log external alertmanager URLs #54127 2022-08-24 13:52:39 -04:00
sender_test.go Alerting: Sanitize invalid label/annotation names for external alertmanagers (#54537) 2022-09-07 11:39:39 -04:00
sender.go Alerting: Sanitize invalid label/annotation names for external alertmanagers (#54537) 2022-09-07 11:39:39 -04:00
testing.go Handle ioutil deprecations (#53526) 2022-08-10 15:37:51 +02:00