You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This change fixes the `custom_details` value in PagerDuty V2 API payloads.
Fixes#2477Fixes#3218
Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
firing: '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
resolved: '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
num_firing: '{{ .Alerts.Firing | len }}'
num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```
The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
CustomDetails map[string]string `json:"custom_details,omitempty"`
```
The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. The result is passed as `custom_details`, part of the JSON payload sent to PagerDuty API V2
Here is an example payload using `.Alerts.Firing`, which returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
"client": "Alertmanager",
...
"custom_details": {
"firing": "Labels:
- alertname = Server_Down
...
Annotations:
- summary = Server is down
...
"
}
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object which is machine readable/parsable by it's fields.
This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see #3322
Signed-off-by: Siavash Safi <[email protected]>
0 commit comments