diff --git a/pkg/services/ngalert/notifier/channels/discord_test.go b/pkg/services/ngalert/notifier/channels/discord_test.go index b14be659713..939189b8d36 100644 --- a/pkg/services/ngalert/notifier/channels/discord_test.go +++ b/pkg/services/ngalert/notifier/channels/discord_test.go @@ -14,6 +14,7 @@ import ( "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/setting" ) func TestDiscordNotifier(t *testing.T) { @@ -48,7 +49,7 @@ func TestDiscordNotifier(t *testing.T) { "color": 1.4037554e+07, "footer": map[string]interface{}{ "icon_url": "https://grafana.com/assets/img/fav32.png", - "text": "Grafana v", + "text": "Grafana v" + setting.BuildVersion, }, "title": "[FIRING:1] (val1)", "url": "http://localhost/alerting/list", @@ -85,7 +86,7 @@ func TestDiscordNotifier(t *testing.T) { "color": 1.4037554e+07, "footer": map[string]interface{}{ "icon_url": "https://grafana.com/assets/img/fav32.png", - "text": "Grafana v", + "text": "Grafana v" + setting.BuildVersion, }, "title": "[FIRING:2] ", "url": "http://localhost/alerting/list", @@ -120,7 +121,7 @@ func TestDiscordNotifier(t *testing.T) { "color": 1.4037554e+07, "footer": map[string]interface{}{ "icon_url": "https://grafana.com/assets/img/fav32.png", - "text": "Grafana v", + "text": "Grafana v" + setting.BuildVersion, }, "title": "[FIRING:1] (val1)", "url": "http://localhost/alerting/list", diff --git a/pkg/services/ngalert/notifier/channels/slack_test.go b/pkg/services/ngalert/notifier/channels/slack_test.go index ba5db25a47a..ce6eef5bba8 100644 --- a/pkg/services/ngalert/notifier/channels/slack_test.go +++ b/pkg/services/ngalert/notifier/channels/slack_test.go @@ -13,6 +13,7 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/secrets/fakes" secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager" + "github.com/grafana/grafana/pkg/setting" "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/types" @@ -61,7 +62,7 @@ func TestSlackNotifier(t *testing.T) { Text: "**Firing**\n\nValue: [no value]\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", Fallback: "[FIRING:1] (val1)", Fields: nil, - Footer: "Grafana v", + Footer: "Grafana v" + setting.BuildVersion, FooterIcon: "https://grafana.com/assets/img/fav32.png", Color: "#D63232", Ts: 0, @@ -96,7 +97,7 @@ func TestSlackNotifier(t *testing.T) { Text: "**Firing**\n\nValue: [no value]\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", Fallback: "[FIRING:1] (val1)", Fields: nil, - Footer: "Grafana v", + Footer: "Grafana v" + setting.BuildVersion, FooterIcon: "https://grafana.com/assets/img/fav32.png", Color: "#D63232", Ts: 0, @@ -138,7 +139,7 @@ func TestSlackNotifier(t *testing.T) { Text: "**Firing**\n\nValue: [no value]\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\nValue: [no value]\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", Fallback: "2 firing, 0 resolved", Fields: nil, - Footer: "Grafana v", + Footer: "Grafana v" + setting.BuildVersion, FooterIcon: "https://grafana.com/assets/img/fav32.png", Color: "#D63232", Ts: 0, diff --git a/pkg/services/ngalert/notifier/channels/victorops_test.go b/pkg/services/ngalert/notifier/channels/victorops_test.go index e9f94d59bec..ca1b556cc25 100644 --- a/pkg/services/ngalert/notifier/channels/victorops_test.go +++ b/pkg/services/ngalert/notifier/channels/victorops_test.go @@ -2,6 +2,7 @@ package channels import ( "context" + "encoding/json" "net/url" "testing" @@ -13,6 +14,7 @@ import ( "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/setting" ) func TestVictoropsNotifier(t *testing.T) { @@ -26,7 +28,7 @@ func TestVictoropsNotifier(t *testing.T) { name string settings string alerts []*types.Alert - expMsg string + expMsg map[string]interface{} expInitError string expMsgError error }{ @@ -41,14 +43,14 @@ func TestVictoropsNotifier(t *testing.T) { }, }, }, - expMsg: `{ - "alert_url": "http://localhost/alerting/list", - "entity_display_name": "[FIRING:1] (val1)", - "entity_id": "6e3538104c14b583da237e9693b76debbc17f0f8058ef20492e5853096cf8733", - "message_type": "CRITICAL", - "monitoring_tool": "Grafana v", - "state_message": "**Firing**\n\nValue: [no value]\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" - }`, + expMsg: map[string]interface{}{ + "alert_url": "http://localhost/alerting/list", + "entity_display_name": "[FIRING:1] (val1)", + "entity_id": "6e3538104c14b583da237e9693b76debbc17f0f8058ef20492e5853096cf8733", + "message_type": "CRITICAL", + "monitoring_tool": "Grafana v" + setting.BuildVersion, + "state_message": "**Firing**\n\nValue: [no value]\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", + }, expMsgError: nil, }, { name: "Multiple alerts", @@ -66,14 +68,14 @@ func TestVictoropsNotifier(t *testing.T) { }, }, }, - expMsg: `{ - "alert_url": "http://localhost/alerting/list", - "entity_display_name": "[FIRING:2] ", - "entity_id": "6e3538104c14b583da237e9693b76debbc17f0f8058ef20492e5853096cf8733", - "message_type": "CRITICAL", - "monitoring_tool": "Grafana v", - "state_message": "**Firing**\n\nValue: [no value]\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\nValue: [no value]\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" - }`, + expMsg: map[string]interface{}{ + "alert_url": "http://localhost/alerting/list", + "entity_display_name": "[FIRING:2] ", + "entity_id": "6e3538104c14b583da237e9693b76debbc17f0f8058ef20492e5853096cf8733", + "message_type": "CRITICAL", + "monitoring_tool": "Grafana v" + setting.BuildVersion, + "state_message": "**Firing**\n\nValue: [no value]\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\nValue: [no value]\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", + }, expMsgError: nil, }, { name: "Error in initing, no URL", @@ -127,7 +129,9 @@ func TestVictoropsNotifier(t *testing.T) { require.NoError(t, err) body = string(b) - require.JSONEq(t, c.expMsg, body) + expJson, err := json.Marshal(c.expMsg) + require.NoError(t, err) + require.JSONEq(t, string(expJson), body) }) } }