mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 14:52:11 +08:00
Alerting: Support custom API URL for PagerDuty integration (#88007)
* fix assert in LINE * fix pagerduty asserts --------- Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
2
go.mod
2
go.mod
@ -86,7 +86,7 @@ require (
|
||||
github.com/googleapis/gax-go/v2 v2.12.3 // @grafana/grafana-backend-group
|
||||
github.com/gorilla/mux v1.8.1 // @grafana/grafana-backend-group
|
||||
github.com/gorilla/websocket v1.5.0 // @grafana/grafana-app-platform-squad
|
||||
github.com/grafana/alerting v0.0.0-20240424080142-bb4f4f429d36 // @grafana/alerting-squad-backend
|
||||
github.com/grafana/alerting v0.0.0-20240517150520-282da04de5ed // @grafana/alerting-squad-backend
|
||||
github.com/grafana/authlib v0.0.0-20240515154731-fe4779055ef4 // @grafana/identity-access-team
|
||||
github.com/grafana/codejen v0.0.3 // @grafana/dataviz-squad
|
||||
github.com/grafana/cuetsy v0.1.11 // @grafana/grafana-as-code
|
||||
|
2
go.sum
2
go.sum
@ -2152,6 +2152,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grafana/alerting v0.0.0-20240424080142-bb4f4f429d36 h1:v4aQ0cde8SCzNRrD2RczzmFolEkXWriSY9tKakAD0ng=
|
||||
github.com/grafana/alerting v0.0.0-20240424080142-bb4f4f429d36/go.mod h1:8nOsn7PWmttOmWiR7bvYIl3VLl+tIq72ZF+1y54w36M=
|
||||
github.com/grafana/alerting v0.0.0-20240517150520-282da04de5ed h1:D03maWtjam4nErgyDfJyI45cg5UtzxiBsCi3hJWICd8=
|
||||
github.com/grafana/alerting v0.0.0-20240517150520-282da04de5ed/go.mod h1:8nOsn7PWmttOmWiR7bvYIl3VLl+tIq72ZF+1y54w36M=
|
||||
github.com/grafana/authlib v0.0.0-20240515154731-fe4779055ef4 h1:Bfa397TXkM0X97MhbCC+fNSwVtg21c0Mg5STes1dRug=
|
||||
github.com/grafana/authlib v0.0.0-20240515154731-fe4779055ef4/go.mod h1:86rRD5P6u2JPWtNWTMOlqlU+YMv2fUvVz/DomA6L7w4=
|
||||
github.com/grafana/codejen v0.0.3 h1:tAWxoTUuhgmEqxJPOLtJoxlPBbMULFwKFOcRsPRPXDw=
|
||||
|
@ -135,6 +135,7 @@ type PagerdutyIntegration struct {
|
||||
Client *string `json:"client,omitempty" yaml:"client,omitempty" hcl:"client"`
|
||||
ClientURL *string `json:"client_url,omitempty" yaml:"client_url,omitempty" hcl:"client_url"`
|
||||
Details *map[string]string `json:"details,omitempty" yaml:"details,omitempty" hcl:"details"`
|
||||
URL *string `json:"url,omitempty" yaml:"url,omitempty" hcl:"url"`
|
||||
}
|
||||
|
||||
type PushoverIntegration struct {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
alertingOpsgenie "github.com/grafana/alerting/receivers/opsgenie"
|
||||
alertingPagerduty "github.com/grafana/alerting/receivers/pagerduty"
|
||||
alertingTemplates "github.com/grafana/alerting/templates"
|
||||
)
|
||||
|
||||
@ -363,6 +364,14 @@ func GetAvailableNotifiers() []*NotifierPlugin {
|
||||
InputType: InputTypeText,
|
||||
PropertyName: "details",
|
||||
},
|
||||
{ //New in 11.1
|
||||
Label: "URL",
|
||||
Description: "The URL to send API requests to",
|
||||
Element: ElementTypeInput,
|
||||
InputType: InputTypeText,
|
||||
Placeholder: alertingPagerduty.DefaultURL,
|
||||
PropertyName: "url",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
|
||||
"github.com/grafana/alerting/receivers"
|
||||
alertingLine "github.com/grafana/alerting/receivers/line"
|
||||
alertingPagerduty "github.com/grafana/alerting/receivers/pagerduty"
|
||||
alertingPushover "github.com/grafana/alerting/receivers/pushover"
|
||||
alertingSlack "github.com/grafana/alerting/receivers/slack"
|
||||
alertingTelegram "github.com/grafana/alerting/receivers/telegram"
|
||||
@ -913,19 +912,17 @@ func TestIntegrationNotificationChannels(t *testing.T) {
|
||||
mockChannel.responses["slack_recvX"] = `{"ok": true}`
|
||||
|
||||
// Overriding some URLs to send to the mock channel.
|
||||
os, opa, ot, opu, ogb, ol, oth := alertingSlack.APIURL, alertingPagerduty.APIURL,
|
||||
os, ot, opu, ogb, ol, oth := alertingSlack.APIURL,
|
||||
alertingTelegram.APIURL, alertingPushover.APIURL, receivers.GetBoundary,
|
||||
alertingLine.APIURL, alertingThreema.APIURL
|
||||
originalTemplate := alertingTemplates.DefaultTemplateString
|
||||
t.Cleanup(func() {
|
||||
alertingSlack.APIURL, alertingPagerduty.APIURL,
|
||||
alertingTelegram.APIURL, alertingPushover.APIURL, receivers.GetBoundary,
|
||||
alertingLine.APIURL, alertingThreema.APIURL = os, opa, ot, opu, ogb, ol, oth
|
||||
alertingSlack.APIURL, alertingTelegram.APIURL, alertingPushover.APIURL, receivers.GetBoundary,
|
||||
alertingLine.APIURL, alertingThreema.APIURL = os, ot, opu, ogb, ol, oth
|
||||
alertingTemplates.DefaultTemplateString = originalTemplate
|
||||
})
|
||||
alertingTemplates.DefaultTemplateString = alertingTemplates.TemplateForTestsString
|
||||
alertingSlack.APIURL = fmt.Sprintf("http://%s/slack_recvX/slack_testX", mockChannel.server.Addr)
|
||||
alertingPagerduty.APIURL = fmt.Sprintf("http://%s/pagerduty_recvX/pagerduty_testX", mockChannel.server.Addr)
|
||||
alertingTelegram.APIURL = fmt.Sprintf("http://%s/telegram_recv/bot%%s/%%s", mockChannel.server.Addr)
|
||||
alertingPushover.APIURL = fmt.Sprintf("http://%s/pushover_recv/pushover_test", mockChannel.server.Addr)
|
||||
alertingLine.APIURL = fmt.Sprintf("http://%s/line_recv/line_test", mockChannel.server.Addr)
|
||||
@ -1902,7 +1899,8 @@ const alertmanagerConfig = `
|
||||
"class": "testclass",
|
||||
"component": "Integration Test",
|
||||
"group": "testgroup",
|
||||
"summary": "Integration Test {{ template \"pagerduty.default.description\" . }}"
|
||||
"summary": "Integration Test {{ template \"pagerduty.default.description\" . }}",
|
||||
"url": "http://CHANNEL_ADDR/pagerduty_recvX/pagerduty_testX"
|
||||
},
|
||||
"secureSettings": {
|
||||
"integrationKey": "pagerduty_recv/pagerduty_test"
|
||||
@ -2467,7 +2465,8 @@ var expAlertmanagerConfigFromAPI = `
|
||||
"component": "Integration Test",
|
||||
"group": "testgroup",
|
||||
"severity": "warning",
|
||||
"summary": "Integration Test {{ template \"pagerduty.default.description\" . }}"
|
||||
"summary": "Integration Test {{ template \"pagerduty.default.description\" . }}",
|
||||
"url": "http://CHANNEL_ADDR/pagerduty_recvX/pagerduty_testX"
|
||||
},
|
||||
"secureFields": {
|
||||
"integrationKey": true
|
||||
@ -2794,7 +2793,7 @@ var expNonEmailNotifications = map[string][]string{
|
||||
}`,
|
||||
},
|
||||
"line_recv/line_test": {
|
||||
`message=%5BFIRING%3A1%5D+LineAlert+%28default%29%0Ahttp%3A%2Flocalhost%3A3000%2Falerting%2Flist%0A%0A%2A%2AFiring%2A%2A%0A%0AValue%3A+A%3D1%0ALabels%3A%0A+-+alertname+%3D+LineAlert%0A+-+grafana_folder+%3D+default%0AAnnotations%3A%0ASource%3A+http%3A%2F%2Flocalhost%3A3000%2Falerting%2Fgrafana%2FUID_LineAlert%2Fview%3ForgId%3D1%0ASilence%3A+http%3A%2F%2Flocalhost%3A3000%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253DLineAlert%26matcher%3Dgrafana_folder%253Ddefault%26orgId%3D1%0A`,
|
||||
`message=%5BFIRING%3A1%5D+LineAlert+%28default%29%0A%2A%2AFiring%2A%2A%0A%0AValue%3A+A%3D1%0ALabels%3A%0A+-+alertname+%3D+LineAlert%0A+-+grafana_folder+%3D+default%0AAnnotations%3A%0ASource%3A+http%3A%2F%2Flocalhost%3A3000%2Falerting%2Fgrafana%2FUID_LineAlert%2Fview%3ForgId%3D1%0ASilence%3A+http%3A%2F%2Flocalhost%3A3000%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253DLineAlert%26matcher%3Dgrafana_folder%253Ddefault%26orgId%3D1%0A`,
|
||||
},
|
||||
"threema_recv/threema_test": {
|
||||
`from=%2A1234567&secret=myapisecret&text=%E2%9A%A0%EF%B8%8F+%5BFIRING%3A1%5D+ThreemaAlert+%28default%29%0A%0A%2AMessage%3A%2A%0A%2A%2AFiring%2A%2A%0A%0AValue%3A+A%3D1%0ALabels%3A%0A+-+alertname+%3D+ThreemaAlert%0A+-+grafana_folder+%3D+default%0AAnnotations%3A%0ASource%3A+http%3A%2F%2Flocalhost%3A3000%2Falerting%2Fgrafana%2FUID_ThreemaAlert%2Fview%3ForgId%3D1%0ASilence%3A+http%3A%2F%2Flocalhost%3A3000%2Falerting%2Fsilence%2Fnew%3Falertmanager%3Dgrafana%26matcher%3Dalertname%253DThreemaAlert%26matcher%3Dgrafana_folder%253Ddefault%26orgId%3D1%0A%0A%2AURL%3A%2A+http%3A%2Flocalhost%3A3000%2Falerting%2Flist%0A&to=abcdefgh`,
|
||||
|
Reference in New Issue
Block a user