Commit 8a991244 by Andrew Rabert Committed by Marcus Efraimsson

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
parent 54ebf174
......@@ -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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment