From 665caa8e08735fcc788492a333ac8db1210f7d50 Mon Sep 17 00:00:00 2001 From: Ricky Moorhouse Date: Fri, 26 May 2017 12:30:56 +0100 Subject: [PATCH 1/2] Include triggering metrics to pagerduty alerts Assist the person receiving the alert in identifying the cause Based on the slack notifier fields this will include upto 4 triggering metrics in the custom details section in the pagerduty incident Fixes #8479 --- pkg/services/alerting/notifiers/pagerduty.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/services/alerting/notifiers/pagerduty.go b/pkg/services/alerting/notifiers/pagerduty.go index 0c98ab00e20..7b3a06c0c6b 100644 --- a/pkg/services/alerting/notifiers/pagerduty.go +++ b/pkg/services/alerting/notifiers/pagerduty.go @@ -74,6 +74,16 @@ func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error { if evalContext.Rule.State == m.AlertStateOK { eventType = "resolve" } + customData := make([]map[string]interface{}, 0) + fieldLimitCount := 4 + for index, evt := range evalContext.EvalMatches { + customData = append(customData, map[string]interface{}{ + evt.Metric: evt.Value, + }) + if index > fieldLimitCount { + break + } + } this.log.Info("Notifying Pagerduty", "event_type", eventType) @@ -81,6 +91,7 @@ func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error { bodyJSON.Set("service_key", this.Key) bodyJSON.Set("description", evalContext.Rule.Name+" - "+evalContext.Rule.Message) bodyJSON.Set("client", "Grafana") + bodyJSON.Set("details", customData) bodyJSON.Set("event_type", eventType) bodyJSON.Set("incident_key", "alertId-"+strconv.FormatInt(evalContext.Rule.Id, 10)) From d355862328252ce5bb7a5fcd3eb7a448be25ea27 Mon Sep 17 00:00:00 2001 From: Vsevolod Polyakov Date: Wed, 20 Sep 2017 13:03:18 +0300 Subject: [PATCH 2/2] Make details more clean in PD description --- pkg/services/alerting/notifiers/pagerduty.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pkg/services/alerting/notifiers/pagerduty.go b/pkg/services/alerting/notifiers/pagerduty.go index 7b3a06c0c6b..3a35b928c96 100644 --- a/pkg/services/alerting/notifiers/pagerduty.go +++ b/pkg/services/alerting/notifiers/pagerduty.go @@ -3,6 +3,8 @@ package notifiers import ( "strconv" + "fmt" + "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/log" @@ -74,15 +76,9 @@ func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error { if evalContext.Rule.State == m.AlertStateOK { eventType = "resolve" } - customData := make([]map[string]interface{}, 0) - fieldLimitCount := 4 - for index, evt := range evalContext.EvalMatches { - customData = append(customData, map[string]interface{}{ - evt.Metric: evt.Value, - }) - if index > fieldLimitCount { - break - } + customData := "Triggered metrics:\n\n" + for _, evt := range evalContext.EvalMatches { + customData = customData + fmt.Sprintf("%s: %v\n", evt.Metric, evt.Value) } this.log.Info("Notifying Pagerduty", "event_type", eventType)