mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
Alerting: add organziation ID to the ngAlert webhook payload (#40189)
* Alerting: add organziation ID to the ngAlert webhook payload
This commit is contained in:
parent
0fe200ce41
commit
d9c0220824
@ -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,
|
||||
|
@ -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"`
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -1884,6 +1884,7 @@ var expNonEmailNotifications = map[string][]string{
|
||||
`{
|
||||
"receiver": "webhook_recv",
|
||||
"status": "firing",
|
||||
"orgId": 1,
|
||||
"alerts": [
|
||||
{
|
||||
"status": "firing",
|
||||
|
Loading…
Reference in New Issue
Block a user