diff --git a/pkg/services/ngalert/notifier/alertmanager.go b/pkg/services/ngalert/notifier/alertmanager.go index c223849f48c..9a827da6362 100644 --- a/pkg/services/ngalert/notifier/alertmanager.go +++ b/pkg/services/ngalert/notifier/alertmanager.go @@ -491,6 +491,7 @@ func (am *Alertmanager) buildReceiverIntegration(r *apimodels.PostableGrafanaRec var ( cfg = &channels.NotificationChannelConfig{ UID: r.UID, + OrgID: am.orgID, Name: r.Name, Type: r.Type, DisableResolveMessage: r.DisableResolveMessage, diff --git a/pkg/services/ngalert/notifier/channels/utils.go b/pkg/services/ngalert/notifier/channels/utils.go index 7a18ffcb6d2..6308553b8e3 100644 --- a/pkg/services/ngalert/notifier/channels/utils.go +++ b/pkg/services/ngalert/notifier/channels/utils.go @@ -55,6 +55,7 @@ func getAlertStatusColor(status model.AlertStatus) string { } type NotificationChannelConfig struct { + OrgID int64 // only used internally UID string `json:"uid"` Name string `json:"name"` Type string `json:"type"` diff --git a/pkg/services/ngalert/notifier/channels/webhook.go b/pkg/services/ngalert/notifier/channels/webhook.go index 4d864b4d3a6..7c456260274 100644 --- a/pkg/services/ngalert/notifier/channels/webhook.go +++ b/pkg/services/ngalert/notifier/channels/webhook.go @@ -26,6 +26,7 @@ type WebhookNotifier struct { MaxAlerts int log log.Logger tmpl *template.Template + orgID int64 } // NewWebHookNotifier is the constructor for @@ -46,6 +47,7 @@ func NewWebHookNotifier(model *NotificationChannelConfig, t *template.Template, DisableResolveMessage: model.DisableResolveMessage, Settings: model.Settings, }), + orgID: model.OrgID, URL: url, User: model.Settings.Get("username").MustString(), Password: fn(context.Background(), model.SecureSettings, "password", model.Settings.Get("password").MustString(), setting.SecretKey), @@ -64,6 +66,7 @@ type webhookMessage struct { Version string `json:"version"` GroupKey string `json:"groupKey"` TruncatedAlerts int `json:"truncatedAlerts"` + OrgID int64 `json:"orgId"` // Deprecated, to be removed in 8.1. // These are present to make migration a little less disruptive. @@ -87,10 +90,10 @@ func (wn *WebhookNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool ExtendedData: data, GroupKey: groupKey.String(), TruncatedAlerts: numTruncated, + OrgID: wn.orgID, Title: tmpl(`{{ template "default.title" . }}`), Message: tmpl(`{{ template "default.message" . }}`), } - if types.Alerts(as...).Status() == model.AlertFiring { msg.State = string(models.AlertStateAlerting) } else { diff --git a/pkg/services/ngalert/notifier/channels/webhook_test.go b/pkg/services/ngalert/notifier/channels/webhook_test.go index a6d8c8046c8..2fc0e6fa2a8 100644 --- a/pkg/services/ngalert/notifier/channels/webhook_test.go +++ b/pkg/services/ngalert/notifier/channels/webhook_test.go @@ -26,6 +26,8 @@ func TestWebhookNotifier(t *testing.T) { require.NoError(t, err) tmpl.ExternalURL = externalURL + orgID := int64(1) + cases := []struct { name string settings string @@ -88,6 +90,7 @@ func TestWebhookNotifier(t *testing.T) { Title: "[FIRING:1] (val1)", State: "alerting", Message: "**Firing**\n\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval1\nDashboard: http://localhost/d/abcd\nPanel: http://localhost/d/abcd?viewPanel=efgh\n", + OrgID: orgID, }, expMsgError: nil, }, { @@ -165,6 +168,7 @@ func TestWebhookNotifier(t *testing.T) { Title: "[FIRING:2] ", State: "alerting", Message: "**Firing**\n\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval1\n\nLabels:\n - alertname = alert1\n - lbl1 = val2\nAnnotations:\n - ann1 = annv2\nSilence: http://localhost/alerting/silence/new?alertmanager=grafana&matchers=alertname%3Dalert1%2Clbl1%3Dval2\n", + OrgID: orgID, }, expMsgError: nil, }, { @@ -183,6 +187,7 @@ func TestWebhookNotifier(t *testing.T) { Name: "webhook_testing", Type: "webhook", Settings: settingsJSON, + OrgID: orgID, } decryptFn := ossencryption.ProvideService().GetDecryptedValue diff --git a/pkg/tests/api/alerting/api_notification_channel_test.go b/pkg/tests/api/alerting/api_notification_channel_test.go index 1a454db205f..db844620d63 100644 --- a/pkg/tests/api/alerting/api_notification_channel_test.go +++ b/pkg/tests/api/alerting/api_notification_channel_test.go @@ -1884,6 +1884,7 @@ var expNonEmailNotifications = map[string][]string{ `{ "receiver": "webhook_recv", "status": "firing", + "orgId": 1, "alerts": [ { "status": "firing",