Skip to content

Commit

Permalink
Merge pull request #2981 from metalmatze/telegram-defaults
Browse files Browse the repository at this point in the history
notify/telegram: Set API URL and ParseMode defaults
  • Loading branch information
gotjosh committed Jul 5, 2022
2 parents a68fcc0 + 2785325 commit d4c2048
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
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

0 comments on commit d4c2048

Please sign in to comment.