|
|
|
@ -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) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|