Browse Source

Alerting: Also include configured AlertRuleTags in Webhooks (#18233)

* added alert rule tags in webhook notifications

* fix: don't include whole list of Tag objects but only key/value pairs in Webhook JSON

* marked webhook alerts to support alert rule tags
Dominic Miglar 6 years ago
parent
commit
32d6740b8f

+ 1 - 1
docs/sources/alerting/notifications.md

@@ -186,7 +186,7 @@ Slack | `slack` | yes | no
 Telegram | `telegram` | yes | no
 Threema | `threema` | yes, external only | no
 VictorOps | `victorops` | yes, external only | no
-Webhook | `webhook` | yes, external only | no
+Webhook | `webhook` | yes, external only | yes
 
 # Enable images in notifications {#external-image-store}
 

+ 8 - 0
pkg/services/alerting/notifiers/webhook.go

@@ -81,6 +81,14 @@ func (wn *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
 	bodyJSON.Set("state", evalContext.Rule.State)
 	bodyJSON.Set("evalMatches", evalContext.EvalMatches)
 
+	tags := make(map[string]string)
+
+	for _, tag := range evalContext.Rule.AlertRuleTags {
+		tags[tag.Key] = tag.Value
+	}
+
+	bodyJSON.Set("tags", tags)
+
 	ruleURL, err := evalContext.GetRuleURL()
 	if err == nil {
 		bodyJSON.Set("ruleUrl", ruleURL)