Skip to content

Commit

Permalink
Alerting: PagerDuty: adding current state to the payload (grafana#29270)
Browse files Browse the repository at this point in the history
* adding state to the payload

* fix test

* fix linter

* documentation payload current state

* Apply suggestions from code review

Co-authored-by: Diana Payton <[email protected]>

Co-authored-by: Diana Payton <[email protected]>
  • Loading branch information
2 people authored and ryantxu committed Mar 30, 2021
1 parent 5dc66b0 commit d49c58c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docs/sources/alerting/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ This might break custom event rules in your PagerDuty rules if you rely on the f
Move any existing rules using `custom_details.myMetric` to `custom_details.queries.myMetric`.
This behavior will become the default in a future version of Grafana.

> Using `dedup_key` tag will override Grafana generated `dedup_key` with a custom key.
> **Note:** The `dedup_key` tag overrides the Grafana-generated `dedup_key` with a custom key.
> **Note:** The `state` tag overrides the current alert state inside the `custom_details` payload.
### Pushover

Expand Down
1 change: 1 addition & 0 deletions pkg/services/alerting/notifiers/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (pn *PagerdutyNotifier) buildEventPayload(evalContext *alerting.EvalContext
eventType = "resolve"
}
customData := simplejson.New()
customData.Set("state", evalContext.Rule.State)
if pn.MessageInDetails {
queries := make(map[string]interface{})
for _, evt := range evalContext.EvalMatches {
Expand Down
18 changes: 12 additions & 6 deletions pkg/services/alerting/notifiers/pagerduty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ func TestPagerdutyNotifier(t *testing.T) {
},
},
"payload": map[string]interface{}{
"component": "Grafana",
"source": "<<PRESENCE>>",
"custom_details": map[string]interface{}{},
"severity": "critical",
"summary": "someRule - someMessage",
"timestamp": "<<PRESENCE>>",
"component": "Grafana",
"source": "<<PRESENCE>>",
"custom_details": map[string]interface{}{
"state": "alerting",
},
"severity": "critical",
"summary": "someRule - someMessage",
"timestamp": "<<PRESENCE>>",
},
"routing_key": "abcdefgh0123456789",
}, payload.Interface(), cmp.Comparer(presenceComparer))
Expand Down Expand Up @@ -231,6 +233,7 @@ func TestPagerdutyNotifier(t *testing.T) {
"queries": map[string]interface{}{
"someMetric": nil,
},
"state": "alerting",
},
"severity": "critical",
"summary": "someRule",
Expand Down Expand Up @@ -303,6 +306,7 @@ func TestPagerdutyNotifier(t *testing.T) {
"severity": "warning",
"dedup_key": "key-" + strings.Repeat("x", 250),
"keyOnly": "",
"state": "alerting",
},
"severity": "warning",
"summary": "someRule - someMessage",
Expand Down Expand Up @@ -380,6 +384,7 @@ func TestPagerdutyNotifier(t *testing.T) {
"component": "aComponent",
"severity": "info",
"keyOnly": "",
"state": "alerting",
},
"severity": "info",
"summary": "someRule - someMessage",
Expand Down Expand Up @@ -458,6 +463,7 @@ func TestPagerdutyNotifier(t *testing.T) {
"component": "aComponent",
"severity": "llama",
"keyOnly": "",
"state": "alerting",
},
"severity": "critical",
"summary": "someRule - someMessage",
Expand Down

0 comments on commit d49c58c

Please sign in to comment.