From 8a991244d5bfe27f97275208c1ac552f0c819a32 Mon Sep 17 00:00:00 2001 From: Andrew Rabert <6550543+nvllsvm@users.noreply.github.com> Date: Fri, 20 Sep 2019 04:39:27 -0400 Subject: [PATCH] Alerting: Truncate PagerDuty summary when greater than 1024 characters (#18730) Requests to PagerDuty fail with an HTTP 400 if the `summary` attribute contains more than 1024 characters, this fixes this. API spec: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 Fixes #18727 --- pkg/services/alerting/notifiers/pagerduty.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/services/alerting/notifiers/pagerduty.go b/pkg/services/alerting/notifiers/pagerduty.go index d771bfd1ad6..c3bcf475c46 100644 --- a/pkg/services/alerting/notifiers/pagerduty.go +++ b/pkg/services/alerting/notifiers/pagerduty.go @@ -88,7 +88,13 @@ func (pn *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error { pn.log.Info("Notifying Pagerduty", "event_type", eventType) payloadJSON := simplejson.New() - payloadJSON.Set("summary", evalContext.Rule.Name+" - "+evalContext.Rule.Message) + + summary := evalContext.Rule.Name + " - " + evalContext.Rule.Message + if len(summary) > 1024 { + summary = summary[0:1024] + } + payloadJSON.Set("summary", summary) + if hostname, err := os.Hostname(); err == nil { payloadJSON.Set("source", hostname) }