mirror of
https://github.com/containrrr/watchtower.git
synced 2024-12-12 09:04:17 +02:00
add slackrus slack notifications
This commit is contained in:
parent
d989254b1a
commit
fd7f8a40ed
22
README.md
22
README.md
@ -189,6 +189,9 @@ Watchtower can send notifications when containers are updated. Notifications are
|
|||||||
The types of notifications to send are passed via the comma-separated option `--notifications` (or corresponding environment variable `WATCHTOWER_NOTIFICATIONS`), which has the following valid values:
|
The types of notifications to send are passed via the comma-separated option `--notifications` (or corresponding environment variable `WATCHTOWER_NOTIFICATIONS`), which has the following valid values:
|
||||||
|
|
||||||
* `email` to send notifications via e-mail
|
* `email` to send notifications via e-mail
|
||||||
|
* `slack` to send notifications through a Slack webhook
|
||||||
|
|
||||||
|
### Notifications via E-Mail
|
||||||
|
|
||||||
To receive notifications by email, the following command-line options, or their corresponding environment variables, can be set:
|
To receive notifications by email, the following command-line options, or their corresponding environment variables, can be set:
|
||||||
|
|
||||||
@ -215,3 +218,22 @@ docker run -d \
|
|||||||
v2tec/watchtower
|
v2tec/watchtower
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Notifications through Slack webhook
|
||||||
|
|
||||||
|
To receive notifications in Slack, add `slack` to the `--notifications` option or the `WATCHTOWER_NOTIFICATIONS` environment variable.
|
||||||
|
|
||||||
|
Additionally, you should set the Slack webhook url using the `--notification-slack-hook-url` option or the `WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL` environment variable.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name watchtower \
|
||||||
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
-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 \
|
||||||
|
v2tec/watchtower
|
||||||
|
```
|
||||||
|
20
glide.lock
generated
20
glide.lock
generated
@ -1,5 +1,5 @@
|
|||||||
hash: 9ddd729b207d71ce16ae9a0282ac87a046b9161ac4f15b108e86a03367172516
|
hash: c0e0c69383b9b665e92c40a5ea69632ea846a645f44654411137c75c5ef5017c
|
||||||
updated: 2017-01-24T20:45:43.1914053+01:00
|
updated: 2017-11-27T11:34:21.283697431+01:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/Azure/go-ansiterm
|
- name: github.com/Azure/go-ansiterm
|
||||||
version: 388960b655244e76e24c75f48631564eaefade62
|
version: 388960b655244e76e24c75f48631564eaefade62
|
||||||
@ -25,7 +25,7 @@ imports:
|
|||||||
- registry/storage/cache/memory
|
- registry/storage/cache/memory
|
||||||
- uuid
|
- uuid
|
||||||
- name: github.com/docker/docker
|
- name: github.com/docker/docker
|
||||||
version: 49bf474f9ed7ce7143a59d1964ff7b7fd9b52178
|
version: 092cba3727bb9b4a2f0e922cd6c0f93ea270e363
|
||||||
subpackages:
|
subpackages:
|
||||||
- api
|
- api
|
||||||
- api/server/httputils
|
- api/server/httputils
|
||||||
@ -110,13 +110,16 @@ imports:
|
|||||||
version: 0eeaf8392f5b04950925b8a69fe70f110fa7cbfc
|
version: 0eeaf8392f5b04950925b8a69fe70f110fa7cbfc
|
||||||
- name: github.com/inconshreveable/mousetrap
|
- name: github.com/inconshreveable/mousetrap
|
||||||
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
|
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
|
||||||
|
- name: github.com/johntdyer/slack-go
|
||||||
|
version: 88ef3038545fa084d81f36e4a6943d112cdd74f6
|
||||||
|
- name: github.com/johntdyer/slackrus
|
||||||
|
version: 3992f319fd0ac349483279ef74742cd787841cba
|
||||||
- name: github.com/mattn/go-shellwords
|
- name: github.com/mattn/go-shellwords
|
||||||
version: f4e566c536cf69158e808ec28ef4182a37fdc981
|
version: f4e566c536cf69158e808ec28ef4182a37fdc981
|
||||||
- name: github.com/Microsoft/go-winio
|
- name: github.com/Microsoft/go-winio
|
||||||
version: 24a3e3d3fc7451805e09d11e11e95d9a0a4f205e
|
version: 24a3e3d3fc7451805e09d11e11e95d9a0a4f205e
|
||||||
- name: github.com/opencontainers/runc
|
- name: github.com/opencontainers/runc
|
||||||
version: 2f7393a47307a16f8cee44a37b262e8b81021e3e
|
version: e8149af2910850602cae998dede29e630d1b8ee1
|
||||||
repo: https://github.com/docker/runc.git
|
|
||||||
subpackages:
|
subpackages:
|
||||||
- libcontainer/configs
|
- libcontainer/configs
|
||||||
- libcontainer/devices
|
- libcontainer/devices
|
||||||
@ -135,10 +138,11 @@ imports:
|
|||||||
- name: github.com/robfig/cron
|
- name: github.com/robfig/cron
|
||||||
version: 9585fd555638e77bba25f25db5c44b41f264aeb7
|
version: 9585fd555638e77bba25f25db5c44b41f264aeb7
|
||||||
- name: github.com/Sirupsen/logrus
|
- name: github.com/Sirupsen/logrus
|
||||||
version: d26492970760ca5d33129d2d799e34be5c4782eb
|
version: ba1b36c82c5e05c4f912a88eab0dcd91a171688f
|
||||||
|
- name: github.com/sirupsen/logrus
|
||||||
|
version: ba1b36c82c5e05c4f912a88eab0dcd91a171688f
|
||||||
- name: github.com/spf13/cobra
|
- name: github.com/spf13/cobra
|
||||||
version: a3c09249f1a24a9d951f2738fb9b9256b8b42fa5
|
version: 1be1d2841c773c01bee8289f55f7463b6e2c2539
|
||||||
repo: https://github.com/dnephin/cobra.git
|
|
||||||
- name: github.com/spf13/pflag
|
- name: github.com/spf13/pflag
|
||||||
version: dabebe21bf790f782ea4c7bbd2efc430de182afd
|
version: dabebe21bf790f782ea4c7bbd2efc430de182afd
|
||||||
- name: github.com/stretchr/objx
|
- name: github.com/stretchr/objx
|
||||||
|
@ -26,3 +26,5 @@ import:
|
|||||||
- context
|
- context
|
||||||
- package: github.com/robfig/cron
|
- package: github.com/robfig/cron
|
||||||
version: 9585fd555638e77bba25f25db5c44b41f264aeb7
|
version: 9585fd555638e77bba25f25db5c44b41f264aeb7
|
||||||
|
- package: github.com/johntdyer/slackrus
|
||||||
|
version: 3992f31
|
||||||
|
21
main.go
21
main.go
@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"github.com/v2tec/watchtower/actions"
|
"github.com/v2tec/watchtower/actions"
|
||||||
"github.com/v2tec/watchtower/container"
|
"github.com/v2tec/watchtower/container"
|
||||||
@ -93,7 +93,7 @@ func main() {
|
|||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "notifications",
|
Name: "notifications",
|
||||||
Value: &cli.StringSlice{},
|
Value: &cli.StringSlice{},
|
||||||
Usage: "notification types to send (valid: email)",
|
Usage: "notification types to send (valid: email, slack)",
|
||||||
EnvVar: "WATCHTOWER_NOTIFICATIONS",
|
EnvVar: "WATCHTOWER_NOTIFICATIONS",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
@ -136,6 +136,23 @@ func main() {
|
|||||||
Usage: "SMTP server password for sending notifications",
|
Usage: "SMTP server password for sending notifications",
|
||||||
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD",
|
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "notification-slack-hook-url",
|
||||||
|
Usage: "The Slack Hook URL to send notifications to",
|
||||||
|
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "notification-slack-identifier",
|
||||||
|
Usage: "A string which will be used to identify the messages coming from this watchtower instance. Default if omitted is \"watchtower\"",
|
||||||
|
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER",
|
||||||
|
Value: "watchtower",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "notification-slack-level",
|
||||||
|
Usage: "The log level used for sending notifications through Slack. Default if omitted is \"info\". Possible values: \"panic\",\"fatal\",\"error\",\"warn\",\"info\" or \"debug\"",
|
||||||
|
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_LEVEL",
|
||||||
|
Value: "info",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
@ -26,6 +26,8 @@ func NewNotifier(c *cli.Context) *Notifier {
|
|||||||
switch t {
|
switch t {
|
||||||
case emailType:
|
case emailType:
|
||||||
tn = newEmailNotifier(c)
|
tn = newEmailNotifier(c)
|
||||||
|
case slackType:
|
||||||
|
tn = newSlackNotifier(c)
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Unknown notification type %q", t)
|
log.Fatalf("Unknown notification type %q", t)
|
||||||
}
|
}
|
||||||
|
38
notifications/slack.go
Normal file
38
notifications/slack.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package notifications
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/johntdyer/slackrus"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
slackType = "slack"
|
||||||
|
)
|
||||||
|
|
||||||
|
type slackTypeNotifier struct {
|
||||||
|
slackrus.SlackrusHook
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSlackNotifier(c *cli.Context) typeNotifier {
|
||||||
|
logLevel, err := log.ParseLevel(c.GlobalString("notification-slack-level"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Slack notifications: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
n := &slackTypeNotifier{
|
||||||
|
SlackrusHook: slackrus.SlackrusHook{
|
||||||
|
HookURL: c.GlobalString("notification-slack-hook-url"),
|
||||||
|
Username: c.GlobalString("notification-slack-identifier"),
|
||||||
|
AcceptedLevels: slackrus.LevelThreshold(logLevel),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
log.AddHook(n)
|
||||||
|
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *slackTypeNotifier) StartNotification() {}
|
||||||
|
|
||||||
|
func (s *slackTypeNotifier) SendNotification() {}
|
Loading…
Reference in New Issue
Block a user