diff --git a/pkg/services/ngalert/notifier/channels/dingding.go b/pkg/services/ngalert/notifier/channels/dingding.go index 5a5f86df3ff..73a4134d4e9 100644 --- a/pkg/services/ngalert/notifier/channels/dingding.go +++ b/pkg/services/ngalert/notifier/channels/dingding.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "net/url" + "path" gokit_log "github.com/go-kit/kit/log" "github.com/pkg/errors" @@ -59,7 +60,7 @@ func (dd *DingDingNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo q := url.Values{ "pc_slide": {"false"}, - "url": {dd.tmpl.ExternalURL.String()}, // TODO: should this be rule URL according to original? + "url": {path.Join(dd.tmpl.ExternalURL.String(), "/alerting/list")}, } // Use special link to auto open the message url outside of Dingding diff --git a/pkg/services/ngalert/notifier/channels/dingding_test.go b/pkg/services/ngalert/notifier/channels/dingding_test.go index 7b6f57520de..f45056edc06 100644 --- a/pkg/services/ngalert/notifier/channels/dingding_test.go +++ b/pkg/services/ngalert/notifier/channels/dingding_test.go @@ -49,7 +49,7 @@ func TestDingdingNotifier(t *testing.T) { expMsg: map[string]interface{}{ "msgtype": "link", "link": map[string]interface{}{ - "messageUrl": "dingtalk://dingtalkclient/page/link?pc_slide=false&url=http%3A%2F%2Flocalhost", + "messageUrl": "dingtalk://dingtalkclient/page/link?pc_slide=false&url=http%3A%2Flocalhost%2Falerting%2Flist", "text": "\n**Firing**\nLabels:\n - alertname = alert1\n - lbl1 = val1\nAnnotations:\n - ann1 = annv1\nSource: \n\n\n\n\n", "title": "[firing:1] (val1)", }, @@ -79,7 +79,7 @@ func TestDingdingNotifier(t *testing.T) { expMsg: map[string]interface{}{ "actionCard": map[string]interface{}{ "singleTitle": "More", - "singleURL": "dingtalk://dingtalkclient/page/link?pc_slide=false&url=http%3A%2F%2Flocalhost", + "singleURL": "dingtalk://dingtalkclient/page/link?pc_slide=false&url=http%3A%2Flocalhost%2Falerting%2Flist", "text": "2 alerts are firing, 0 are resolved", "title": "[firing:2] ", }, diff --git a/pkg/services/ngalert/notifier/channels/slack.go b/pkg/services/ngalert/notifier/channels/slack.go index 8b9c1a264ce..de02f75455f 100644 --- a/pkg/services/ngalert/notifier/channels/slack.go +++ b/pkg/services/ngalert/notifier/channels/slack.go @@ -10,6 +10,7 @@ import ( "net" "net/http" "net/url" + "path" "regexp" "strings" "time" @@ -256,7 +257,7 @@ func (sn *SlackNotifier) buildSlackMessage(ctx context.Context, as []*types.Aler Footer: "Grafana v" + setting.BuildVersion, FooterIcon: FooterIconURL, Ts: time.Now().Unix(), - TitleLink: "TODO: rule URL", + TitleLink: path.Join(sn.tmpl.ExternalURL.String(), "/alerting/list"), Text: tmpl(sn.Text), Fields: nil, // TODO. Should be a config. }, diff --git a/pkg/services/ngalert/notifier/channels/slack_test.go b/pkg/services/ngalert/notifier/channels/slack_test.go index f82dc3e444d..02591d2aca6 100644 --- a/pkg/services/ngalert/notifier/channels/slack_test.go +++ b/pkg/services/ngalert/notifier/channels/slack_test.go @@ -59,7 +59,7 @@ func TestSlackNotifier(t *testing.T) { Attachments: []attachment{ { Title: "[FIRING:1] (val1)", - TitleLink: "TODO: rule URL", + TitleLink: "http:/localhost/alerting/list", Text: "", Fallback: "[FIRING:1] (val1)", Fields: nil, @@ -95,7 +95,7 @@ func TestSlackNotifier(t *testing.T) { Attachments: []attachment{ { Title: "[FIRING:1] (val1)", - TitleLink: "TODO: rule URL", + TitleLink: "http:/localhost/alerting/list", Text: "", Fallback: "[FIRING:1] (val1)", Fields: nil, @@ -138,7 +138,7 @@ func TestSlackNotifier(t *testing.T) { Attachments: []attachment{ { Title: "2 firing, 0 resolved", - TitleLink: "TODO: rule URL", + TitleLink: "http:/localhost/alerting/list", Text: "", Fallback: "2 firing, 0 resolved", Fields: nil, diff --git a/pkg/services/ngalert/notifier/channels/teams.go b/pkg/services/ngalert/notifier/channels/teams.go index 6f376f01b9b..c9bfe4894ce 100644 --- a/pkg/services/ngalert/notifier/channels/teams.go +++ b/pkg/services/ngalert/notifier/channels/teams.go @@ -3,6 +3,7 @@ package channels import ( "context" "encoding/json" + "path" gokit_log "github.com/go-kit/kit/log" "github.com/pkg/errors" @@ -75,7 +76,8 @@ func (tn *TeamsNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, "name": "View Rule", "targets": []map[string]interface{}{ { - "os": "default", "uri": "", // TODO: add the rule URL here. + "os": "default", + "uri": path.Join(tn.tmpl.ExternalURL.String(), "/alerting/list"), }, }, }, diff --git a/pkg/services/ngalert/notifier/channels/teams_test.go b/pkg/services/ngalert/notifier/channels/teams_test.go index d6b063337e8..f032e858470 100644 --- a/pkg/services/ngalert/notifier/channels/teams_test.go +++ b/pkg/services/ngalert/notifier/channels/teams_test.go @@ -63,7 +63,7 @@ func TestTeamsNotifier(t *testing.T) { "@context": "http://schema.org", "@type": "OpenUri", "name": "View Rule", - "targets": []map[string]interface{}{{"os": "default", "uri": ""}}, + "targets": []map[string]interface{}{{"os": "default", "uri": "http:/localhost/alerting/list"}}, }, }, }, @@ -105,7 +105,7 @@ func TestTeamsNotifier(t *testing.T) { "@context": "http://schema.org", "@type": "OpenUri", "name": "View Rule", - "targets": []map[string]interface{}{{"os": "default", "uri": ""}}, + "targets": []map[string]interface{}{{"os": "default", "uri": "http:/localhost/alerting/list"}}, }, }, },