From 00d1fc6faad9d5076ede97e6b3ab97bb8c7a2c59 Mon Sep 17 00:00:00 2001 From: Xabier Larrakoetxea Date: Fri, 20 Dec 2019 16:13:00 +0100 Subject: [PATCH] Telegram required arguments are not required when using notification dry run mode Signed-off-by: Xabier Larrakoetxea --- CHANGELOG.md | 4 ++++ cmd/alertgram/config.go | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 969307a..0a3263e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Forward alerts by custom chat ID based on alert labels. +### Changed + +- Telegram required flags/envs are not required when using notify dry run mode. + ## [0.2.1] - 2019-12-17 ### Added diff --git a/cmd/alertgram/config.go b/cmd/alertgram/config.go index e2e41fb..53f51c9 100644 --- a/cmd/alertgram/config.go +++ b/cmd/alertgram/config.go @@ -1,6 +1,7 @@ package main import ( + "errors" "os" "time" @@ -90,8 +91,8 @@ func (c *Config) registerFlags() { c.app.Flag("alertmanager.webhook-path", descAMWebhookPath).Default(defAMWebhookPath).StringVar(&c.AlertmanagerWebhookPath) c.app.Flag("alertmanager.chat-id-query-string", descAMChatIDQS).Default(defAMChatIDQS).StringVar(&c.AlertmanagerChatIDQQueryString) c.app.Flag("alertmanager.dead-mans-switch-path", descAMDMSPath).Default(defAMDMSPath).StringVar(&c.AlertmanagerDMSPath) - c.app.Flag("telegram.api-token", descTelegramAPIToken).Required().StringVar(&c.TeletramAPIToken) - c.app.Flag("telegram.chat-id", descTelegramDefChatID).Required().Int64Var(&c.TelegramChatID) + c.app.Flag("telegram.api-token", descTelegramAPIToken).StringVar(&c.TeletramAPIToken) + c.app.Flag("telegram.chat-id", descTelegramDefChatID).Int64Var(&c.TelegramChatID) c.app.Flag("metrics.listen-address", descMetricsListenAddr).Default(defMetricsListenAddr).StringVar(&c.MetricsListenAddr) c.app.Flag("metrics.path", descMetricsPath).Default(defMetricsPath).StringVar(&c.MetricsPath) c.app.Flag("metrics.health-path", descMetricsHCPath).Default(defMetricsHCPath).StringVar(&c.MetricsHCPath) @@ -105,5 +106,14 @@ func (c *Config) registerFlags() { } func (c *Config) validate() error { + if !c.NotifyDryRun { + if c.TeletramAPIToken == "" { + return errors.New("telegram api token is required") + } + + if c.TelegramChatID == 0 { + return errors.New("telegram default chat ID is required") + } + } return nil }