diff --git a/pkg/services/alerting/notifiers/pagerduty.go b/pkg/services/alerting/notifiers/pagerduty.go index 46def447763..0557f5de733 100644 --- a/pkg/services/alerting/notifiers/pagerduty.go +++ b/pkg/services/alerting/notifiers/pagerduty.go @@ -168,7 +168,7 @@ func (pn *PagerdutyNotifier) buildEventPayload(evalContext *alerting.EvalContext } var summary string - if pn.MessageInDetails { + if pn.MessageInDetails || evalContext.Rule.Message == "" { summary = evalContext.Rule.Name } else { summary = evalContext.Rule.Name + " - " + evalContext.Rule.Message diff --git a/pkg/services/alerting/notifiers/pagerduty_test.go b/pkg/services/alerting/notifiers/pagerduty_test.go index 4057b20bf63..7d4ae74201f 100644 --- a/pkg/services/alerting/notifiers/pagerduty_test.go +++ b/pkg/services/alerting/notifiers/pagerduty_test.go @@ -173,6 +173,62 @@ func TestPagerdutyNotifier(t *testing.T) { So(diff, ShouldBeEmpty) }) + Convey("should return properly formatted default v2 event payload with empty message", func() { + json := `{ + "integrationKey": "abcdefgh0123456789", + "autoResolve": false + }` + + settingsJSON, err := simplejson.NewJson([]byte(json)) + So(err, ShouldBeNil) + + model := &models.AlertNotification{ + Name: "pagerduty_testing", + Type: "pagerduty", + Settings: settingsJSON, + } + + not, err := NewPagerdutyNotifier(model) + So(err, ShouldBeNil) + + pagerdutyNotifier := not.(*PagerdutyNotifier) + evalContext := alerting.NewEvalContext(context.Background(), &alerting.Rule{ + ID: 0, + Name: "someRule", + State: models.AlertStateAlerting, + }, &validations.OSSPluginRequestValidator{}) + evalContext.IsTestRun = true + + payloadJSON, err := pagerdutyNotifier.buildEventPayload(evalContext) + So(err, ShouldBeNil) + payload, err := simplejson.NewJson(payloadJSON) + So(err, ShouldBeNil) + + diff := cmp.Diff(map[string]interface{}{ + "client": "Grafana", + "client_url": "", + "dedup_key": "alertId-0", + "event_action": "trigger", + "links": []interface{}{ + map[string]interface{}{ + "href": "", + }, + }, + "payload": map[string]interface{}{ + "component": "Grafana", + "source": "<>", + "custom_details": map[string]interface{}{ + "state": "alerting", + }, + "severity": "critical", + "summary": "someRule", + "timestamp": "<>", + }, + "routing_key": "abcdefgh0123456789", + }, payload.Interface(), cmp.Comparer(presenceComparer)) + So(diff, ShouldBeEmpty) + }) + Convey("should return properly formatted payload with message moved to details", func() { json := `{ "integrationKey": "abcdefgh0123456789",