mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix global state sensitivity in notifier channel tests (#43508)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user