diff --git a/config/notifiers.go b/config/notifiers.go index f7f627c879..52206bf7db 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -344,6 +344,9 @@ type WebhookConfig struct { // URL to send POST request to. URL string `yaml:"url" json:"url"` + + // JSON message which will be sent instead of serialized data object + Message string `yaml:"message,omitempty" json:"message,omitempty"` } // UnmarshalYAML implements the yaml.Unmarshaler interface. diff --git a/notify/impl.go b/notify/impl.go index 8f3b555d2c..f069ac0358 100644 --- a/notify/impl.go +++ b/notify/impl.go @@ -147,7 +147,11 @@ type WebhookMessage struct { // Notify implements the Notifier interface. func (w *Webhook) Notify(ctx context.Context, alerts ...*types.Alert) (bool, error) { - data := w.tmpl.Data(receiverName(ctx, w.logger), groupLabels(ctx, w.logger), alerts...) + var err error + var ( + data = w.tmpl.Data(receiverName(ctx, w.logger), groupLabels(ctx, w.logger), alerts...) + tmplText = tmplText(w.tmpl, data, &err) + ) groupKey, ok := GroupKey(ctx) if !ok { @@ -161,9 +165,18 @@ func (w *Webhook) Notify(ctx context.Context, alerts ...*types.Alert) (bool, err } var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(msg); err != nil { - return false, err - } + + if messageText := tmplText(w.conf.Message); messageText != "" { + _, err := buf.WriteString(messageText) + + if err != nil { + return false, err + } + } else { + if err := json.NewEncoder(&buf).Encode(msg); err != nil { + return false, err + } + } req, err := http.NewRequest("POST", w.conf.URL, &buf) if err != nil {