Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notify/telegram: Set API URL and ParseMode defaults #2981

Merged
merged 3 commits into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions config/notifiers.go
Expand Up @@ -143,7 +143,7 @@ var (
},
DisableNotifications: false,
Message: `{{ template "telegram.default.message" . }}`,
ParseMode: "MarkdownV2",
ParseMode: "HTML",
}
)

Expand Down Expand Up @@ -661,9 +661,6 @@ func (c *TelegramConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
if c.ChatID == 0 {
return fmt.Errorf("missing chat_id on telegram_config")
}
if c.APIUrl == nil {
return fmt.Errorf("missing api_url on telegram_config")
}
if c.ParseMode != "" &&
c.ParseMode != "Markdown" &&
c.ParseMode != "MarkdownV2" &&
Expand Down
26 changes: 25 additions & 1 deletion notify/telegram/telegram_test.go
Expand Up @@ -21,13 +21,37 @@ import (
"github.com/go-kit/log"
commoncfg "github.com/prometheus/common/config"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"

"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/notify/test"
)

func TestTelegramUnmarshal(t *testing.T) {
in := `
route:
receiver: test
receivers:
- name: test
telegram_configs:
- chat_id: 1234
bot_token: secret
`
var c config.Config
err := yaml.Unmarshal([]byte(in), &c)
require.NoError(t, err)

require.Len(t, c.Receivers, 1)
require.Len(t, c.Receivers[0].TelegramConfigs, 1)

require.Equal(t, "https://api.telegram.org", c.Receivers[0].TelegramConfigs[0].APIUrl.String())
require.Equal(t, config.Secret("secret"), c.Receivers[0].TelegramConfigs[0].BotToken)
require.Equal(t, int64(1234), c.Receivers[0].TelegramConfigs[0].ChatID)
require.Equal(t, "HTML", c.Receivers[0].TelegramConfigs[0].ParseMode)
}

func TestTelegramRetry(t *testing.T) {
// Fake url for testing purpouses
// Fake url for testing purposes
fakeURL := config.URL{
URL: &url.URL{
Scheme: "https",
Expand Down