Skip to content

Commit d4c2048

Browse files
authored
Merge pull request #2981 from metalmatze/telegram-defaults
notify/telegram: Set API URL and ParseMode defaults
2 parents a68fcc0 + 2785325 commit d4c2048

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

config/notifiers.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var (
143143
},
144144
DisableNotifications: false,
145145
Message: `{{ template "telegram.default.message" . }}`,
146-
ParseMode: "MarkdownV2",
146+
ParseMode: "HTML",
147147
}
148148
)
149149

@@ -661,9 +661,6 @@ func (c *TelegramConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
661661
if c.ChatID == 0 {
662662
return fmt.Errorf("missing chat_id on telegram_config")
663663
}
664-
if c.APIUrl == nil {
665-
return fmt.Errorf("missing api_url on telegram_config")
666-
}
667664
if c.ParseMode != "" &&
668665
c.ParseMode != "Markdown" &&
669666
c.ParseMode != "MarkdownV2" &&

notify/telegram/telegram_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,37 @@ import (
2121
"github.com/go-kit/log"
2222
commoncfg "github.com/prometheus/common/config"
2323
"github.com/stretchr/testify/require"
24+
"gopkg.in/yaml.v2"
2425

2526
"github.com/prometheus/alertmanager/config"
2627
"github.com/prometheus/alertmanager/notify/test"
2728
)
2829

30+
func TestTelegramUnmarshal(t *testing.T) {
31+
in := `
32+
route:
33+
receiver: test
34+
receivers:
35+
- name: test
36+
telegram_configs:
37+
- chat_id: 1234
38+
bot_token: secret
39+
`
40+
var c config.Config
41+
err := yaml.Unmarshal([]byte(in), &c)
42+
require.NoError(t, err)
43+
44+
require.Len(t, c.Receivers, 1)
45+
require.Len(t, c.Receivers[0].TelegramConfigs, 1)
46+
47+
require.Equal(t, "https://api.telegram.org", c.Receivers[0].TelegramConfigs[0].APIUrl.String())
48+
require.Equal(t, config.Secret("secret"), c.Receivers[0].TelegramConfigs[0].BotToken)
49+
require.Equal(t, int64(1234), c.Receivers[0].TelegramConfigs[0].ChatID)
50+
require.Equal(t, "HTML", c.Receivers[0].TelegramConfigs[0].ParseMode)
51+
}
52+
2953
func TestTelegramRetry(t *testing.T) {
30-
// Fake url for testing purpouses
54+
// Fake url for testing purposes
3155
fakeURL := config.URL{
3256
URL: &url.URL{
3357
Scheme: "https",

0 commit comments

Comments
 (0)