From 5246d1a20e9a9d418f196ae70653db2ea1f4f809 Mon Sep 17 00:00:00 2001 From: Max H <10329648+8ear@users.noreply.github.com> Date: Wed, 9 Oct 2019 09:18:39 +0200 Subject: [PATCH 1/7] Update email.go Added SubjectTag as variable --- pkg/notifications/email.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/notifications/email.go b/pkg/notifications/email.go index b5ef979..ef6b3d7 100644 --- a/pkg/notifications/email.go +++ b/pkg/notifications/email.go @@ -24,7 +24,7 @@ const ( // We work around that by holding on to log entries until the update cycle is done. type emailTypeNotifier struct { From, To string - Server, User, Password string + Server, User, Password, SubjectTag string Port int tlsSkipVerify bool entries []*log.Entry @@ -43,6 +43,7 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie port, _ := flags.GetInt("notification-email-server-port") tlsSkipVerify, _ := flags.GetBool("notification-email-server-tls-skip-verify") delay, _ := flags.GetInt("notification-email-delay") + subjecttag, _ := flags.GetInt("notification-email-subjecttag") n := &emailTypeNotifier{ From: from, @@ -54,6 +55,7 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie tlsSkipVerify: tlsSkipVerify, logLevels: acceptedLogLevels, delay: time.Duration(delay) * time.Second, + SubjectTag: subjecttag, } log.AddHook(n) @@ -62,7 +64,11 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie } func (e *emailTypeNotifier) buildMessage(entries []*log.Entry) []byte { - emailSubject := "Watchtower updates" + if SubjectTag == nil { + emailSubject := "Watchtower updates" + } else { + emailSubject := SubjectTag + " Watchtower updates" + } if hostname, err := os.Hostname(); err == nil { emailSubject += " on " + hostname } From 220dc5add45173558fd655a13bf90419ebd4dec7 Mon Sep 17 00:00:00 2001 From: Max H <10329648+8ear@users.noreply.github.com> Date: Wed, 9 Oct 2019 09:20:07 +0200 Subject: [PATCH 2/7] Update email.go --- pkg/notifications/email.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/notifications/email.go b/pkg/notifications/email.go index ef6b3d7..fdc8fee 100644 --- a/pkg/notifications/email.go +++ b/pkg/notifications/email.go @@ -43,7 +43,7 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie port, _ := flags.GetInt("notification-email-server-port") tlsSkipVerify, _ := flags.GetBool("notification-email-server-tls-skip-verify") delay, _ := flags.GetInt("notification-email-delay") - subjecttag, _ := flags.GetInt("notification-email-subjecttag") + subjecttag, _ := flags.GetString("notification-email-subjecttag") n := &emailTypeNotifier{ From: from, From 505a5ec71577ec3a3bb742fafece703ea73e01dd Mon Sep 17 00:00:00 2001 From: Max H <10329648+8ear@users.noreply.github.com> Date: Wed, 9 Oct 2019 09:25:24 +0200 Subject: [PATCH 3/7] Update email.go --- pkg/notifications/email.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/notifications/email.go b/pkg/notifications/email.go index fdc8fee..7fb1500 100644 --- a/pkg/notifications/email.go +++ b/pkg/notifications/email.go @@ -64,6 +64,9 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie } func (e *emailTypeNotifier) buildMessage(entries []*log.Entry) []byte { + // If variable SubjectTag is empty define emailSubject as "Watchtower updates". + // If variable SubjectTag is set define emailSubject as "$SubjectTag Watchtower updates" + // For example: SubjectTag=[Server Munich] -> "[Server Munich] Watchtower updates ..." if SubjectTag == nil { emailSubject := "Watchtower updates" } else { From fd2a006c6bf8024e3cc69825da38cdb0fb7ca0d9 Mon Sep 17 00:00:00 2001 From: Max H <10329648+8ear@users.noreply.github.com> Date: Tue, 15 Oct 2019 16:41:40 +0200 Subject: [PATCH 4/7] Update email.go --- pkg/notifications/email.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/notifications/email.go b/pkg/notifications/email.go index 7fb1500..4916d40 100644 --- a/pkg/notifications/email.go +++ b/pkg/notifications/email.go @@ -64,10 +64,7 @@ func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie } func (e *emailTypeNotifier) buildMessage(entries []*log.Entry) []byte { - // If variable SubjectTag is empty define emailSubject as "Watchtower updates". - // If variable SubjectTag is set define emailSubject as "$SubjectTag Watchtower updates" - // For example: SubjectTag=[Server Munich] -> "[Server Munich] Watchtower updates ..." - if SubjectTag == nil { + if SubjectTag == "" { emailSubject := "Watchtower updates" } else { emailSubject := SubjectTag + " Watchtower updates" From 6840a8c3cf2678f7937d75530b0661b7932c345a Mon Sep 17 00:00:00 2001 From: Max H <10329648+8ear@users.noreply.github.com> Date: Tue, 15 Oct 2019 16:48:58 +0200 Subject: [PATCH 5/7] Update flags.go --- internal/flags/flags.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 6e9ea55..971afa6 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -146,7 +146,7 @@ func RegisterNotificationFlags(rootCmd *cobra.Command) { "", viper.GetInt("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT"), "SMTP server port to send notification emails through") - + flags.BoolP( "notification-email-server-tls-skip-verify", "", @@ -168,6 +168,12 @@ Should only be used for testing. viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD"), "SMTP server password for sending notifications") + flags.StringP( + "notification-email-subjecttag", + "", + viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG"), + "Subject prefix tag for notifications via mail") + flags.StringP( "notification-slack-hook-url", "", @@ -232,6 +238,7 @@ func SetDefaults() { viper.SetDefault("WATCHTOWER_NOTIFICATIONS", []string{}) viper.SetDefault("WATCHTOWER_NOTIFICATIONS_LEVEL", "info") viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT", 25) + viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG", "") viper.SetDefault("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", "watchtower") } From 9198f8972befe6f78075f5d652ef0cb5d7ed1d5d Mon Sep 17 00:00:00 2001 From: Max H <10329648+8ear@users.noreply.github.com> Date: Tue, 15 Oct 2019 16:51:13 +0200 Subject: [PATCH 6/7] Update flags.go --- internal/flags/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 971afa6..b2f9187 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -146,7 +146,7 @@ func RegisterNotificationFlags(rootCmd *cobra.Command) { "", viper.GetInt("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT"), "SMTP server port to send notification emails through") - + flags.BoolP( "notification-email-server-tls-skip-verify", "", From 8b2eda7bdf126fa202eb2b57c8fbd1a4b5287c4c Mon Sep 17 00:00:00 2001 From: Simon Aronsson Date: Sun, 17 Nov 2019 11:09:14 +0100 Subject: [PATCH 7/7] Update notifications.md --- docs/notifications.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/notifications.md b/docs/notifications.md index 5741566..22da93e 100644 --- a/docs/notifications.md +++ b/docs/notifications.md @@ -27,6 +27,7 @@ To receive notifications by email, the following command-line options, or their - `--notification-email-server-user` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER`): The username to authenticate with the SMTP server with. - `--notification-email-server-password` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD`): The password to authenticate with the SMTP server with. - `--notification-email-delay` (env. `WATCHTOWER_NOTIFICATION_EMAIL_DELAY`): Delay before sending notifications expressed in seconds. +- `--notification-email-subjecttag` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG`): Prefix to include in the subject tag. Useful when running multiple watchtowers. Example: