Alerting: PagerDuty: adding current state to the payload (#29270)

* adding state to the payload

* fix test

* fix linter

* documentation payload current state

* Apply suggestions from code review

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
This commit is contained in:
Labesse Kévin
2021-03-02 17:50:51 +01:00
committed by GitHub
parent 88ac1cf173
commit bd0d051438
3 changed files with 16 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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))
@@ -231,6 +233,7 @@ func TestPagerdutyNotifier(t *testing.T) {
"queries": map[string]interface{}{
"someMetric": nil,
},
"state": "alerting",
},
"severity": "critical",
"summary": "someRule",
@@ -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",
@@ -380,6 +384,7 @@ func TestPagerdutyNotifier(t *testing.T) {
"component": "aComponent",
"severity": "info",
"keyOnly": "",
"state": "alerting",
},
"severity": "info",
"summary": "someRule - someMessage",
@@ -458,6 +463,7 @@ func TestPagerdutyNotifier(t *testing.T) {
"component": "aComponent",
"severity": "llama",
"keyOnly": "",
"state": "alerting",
},
"severity": "critical",
"summary": "someRule - someMessage",