From da41afc1d763e8a1c088120fb576068740a71c2f Mon Sep 17 00:00:00 2001 From: Mario Tacke Date: Sun, 7 Apr 2019 08:38:20 -0700 Subject: [PATCH] Add Slack Channel, IconEmoji, and IconURL options (#241) --- README.md | 8 ++++++++ main.go | 15 +++++++++++++++ notifications/slack.go | 3 +++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 67db06d..06868e6 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,11 @@ Additionally, you should set the Slack webhook url using the `--notification-sla By default, watchtower will send messages under the name `watchtower`, you can customize this string through the `--notification-slack-identifier` option or the `WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER` environment variable. +Other, optional, variables include: +- `--notification-slack-channel` (env. `WATCHTOWER_NOTIFICATION_SLACK_CHANNEL`): A string which overrides the webhook's default channel. Example: #my-custom-channel. +- `--notification-slack-icon-emoji` (env. `WATCHTOWER_NOTIFICATION_SLACK_ICON_EMOJI`): An [emoji code](https://www.webpagefx.com/tools/emoji-cheat-sheet/) string to use in place of the default icon. +- `--notification-slack-icon-url` (env. `WATCHTOWER_NOTIFICATION_SLACK_ICON_URL`): An icon image URL string to use in place of the default icon. + Example: ```bash @@ -283,6 +288,9 @@ docker run -d \ -e WATCHTOWER_NOTIFICATIONS=slack \ -e WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL="https://hooks.slack.com/services/xxx/yyyyyyyyyyyyyyy" \ -e WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER=watchtower-server-1 \ + -e WATCHTOWER_NOTIFICATION_SLACK_CHANNEL=#my-custom-channel \ + -e WATCHTOWER_NOTIFICATION_SLACK_ICON_EMOJI=:whale: \ + -e WATCHTOWER_NOTIFICATION_SLACK_ICON_URL= \ containrrr/watchtower ``` diff --git a/main.go b/main.go index fc853fe..8a34d67 100644 --- a/main.go +++ b/main.go @@ -162,6 +162,21 @@ func main() { EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", Value: "watchtower", }, + cli.StringFlag{ + Name: "notification-slack-channel", + Usage: "A string which overrides the webhook's default channel. Example: #my-custom-channel", + EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_CHANNEL", + }, + cli.StringFlag{ + Name: "notification-slack-icon-emoji", + Usage: "An emoji code string to use in place of the default icon", + EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_ICON_EMOJI", + }, + cli.StringFlag{ + Name: "notification-slack-icon-url", + Usage: "An icon image URL string to use in place of the default icon", + EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_ICON_URL", + }, cli.StringFlag{ Name: "notification-msteams-hook", Usage: "The MSTeams WebHook URL to send notifications to", diff --git a/notifications/slack.go b/notifications/slack.go index dd44f29..08f8d3b 100644 --- a/notifications/slack.go +++ b/notifications/slack.go @@ -19,6 +19,9 @@ func newSlackNotifier(c *cli.Context, acceptedLogLevels []log.Level) typeNotifie SlackrusHook: slackrus.SlackrusHook{ HookURL: c.GlobalString("notification-slack-hook-url"), Username: c.GlobalString("notification-slack-identifier"), + Channel: c.GlobalString("notification-slack-channel"), + IconEmoji: c.GlobalString("notification-slack-icon-emoji"), + IconURL: c.GlobalString("notification-slack-icon-url"), AcceptedLevels: acceptedLogLevels, }, }