Alerting: Add support for images in Telegram (#51433)

This commit is contained in:
George Robinson
2022-06-28 09:39:40 +01:00
committed by GitHub
parent a7f1ca133e
commit 5053468c65
3 changed files with 137 additions and 90 deletions
@@ -721,7 +721,7 @@ func TestNotificationChannels(t *testing.T) {
channels.DefaultTemplateString = channels.TemplateForTestsString
channels.SlackAPIEndpoint = fmt.Sprintf("http://%s/slack_recvX/slack_testX", mockChannel.server.Addr)
channels.PagerdutyEventAPIURL = fmt.Sprintf("http://%s/pagerduty_recvX/pagerduty_testX", mockChannel.server.Addr)
channels.TelegramAPIURL = fmt.Sprintf("http://%s/telegram_recv/bot%%s", mockChannel.server.Addr)
channels.TelegramAPIURL = fmt.Sprintf("http://%s/telegram_recv/bot%%s/%%s", mockChannel.server.Addr)
channels.PushoverEndpoint = fmt.Sprintf("http://%s/pushover_recv/pushover_test", mockChannel.server.Addr)
channels.LineNotifyURL = fmt.Sprintf("http://%s/line_recv/line_test", mockChannel.server.Addr)
channels.ThreemaGwBaseURL = fmt.Sprintf("http://%s/threema_recv/threema_test", mockChannel.server.Addr)
@@ -932,8 +932,8 @@ func (nc *mockNotificationChannel) ServeHTTP(res http.ResponseWriter, req *http.
nc.receivedNotificationsMtx.Lock()
defer nc.receivedNotificationsMtx.Unlock()
urlParts := strings.Split(req.URL.String(), "/")
key := fmt.Sprintf("%s/%s", urlParts[len(urlParts)-2], urlParts[len(urlParts)-1])
paths := strings.Split(req.URL.Path[1:], "/")
key := strings.Join(paths[0:2], "/")
body := getBody(nc.t, req.Body)
nc.receivedNotifications[key] = append(nc.receivedNotifications[key], body)
@@ -973,7 +973,7 @@ func (nc *mockNotificationChannel) matchesExpNotifications(t *testing.T, exp map
case "slack_recv1/slack_test_without_token":
// It has a time component "ts".
r1 = regexp.MustCompile(`.*"ts"\s*:\s*([0-9]+)`)
case "sensugo/events":
case "sensugo_recv/sensugo_test":
// It has a time component "ts".
r1 = regexp.MustCompile(`.*"issued"\s*:\s*([0-9]+)`)
case "pagerduty_recvX/pagerduty_testX":
@@ -985,7 +985,7 @@ func (nc *mockNotificationChannel) matchesExpNotifications(t *testing.T, exp map
case "victorops_recv/victorops_test":
// It has a time component "timestamp".
r1 = regexp.MustCompile(`.*"timestamp"\s*:\s*([0-9]+)`)
case "v1/alerts":
case "alertmanager_recv/alertmanager_test":
// It has a changing time fields.
r1 = regexp.MustCompile(`.*"startsAt"\s*:\s*"([^"]+)"`)
r2 = regexp.MustCompile(`.*"UpdatedAt"\s*:\s*"([^"]+)"`)
@@ -993,7 +993,7 @@ func (nc *mockNotificationChannel) matchesExpNotifications(t *testing.T, exp map
if r1 != nil {
parts := r1.FindStringSubmatch(actVals[i])
require.Len(t, parts, 2)
if expKey == "v1/alerts" {
if expKey == "alertmanager_recv/alertmanager_test" {
// 2 fields for Prometheus Alertmanager.
parts2 := r2.FindStringSubmatch(actVals[i])
require.Len(t, parts2, 2)
@@ -2277,7 +2277,7 @@ var expNonEmailNotifications = map[string][]string{
"username": "Grafana"
}`,
},
"sensugo/events": {
"sensugo_recv/sensugo_test": {
`{
"check": {
"handlers": null,
@@ -2396,7 +2396,7 @@ var expNonEmailNotifications = map[string][]string{
}`,
},
// Prometheus Alertmanager.
"v1/alerts": {
"alertmanager_recv/alertmanager_test": {
`[
{
"labels": {