mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 14:10:12 +01:00
Made the notification level flag global for all notification types.
This commit is contained in:
parent
4ac08dfb30
commit
e1ead2f46f
5 changed files with 26 additions and 24 deletions
|
|
@ -28,9 +28,10 @@ type emailTypeNotifier struct {
|
|||
Port int
|
||||
tlsSkipVerify bool
|
||||
entries []*log.Entry
|
||||
logLevels []log.Level
|
||||
}
|
||||
|
||||
func newEmailNotifier(c *cli.Context) typeNotifier {
|
||||
func newEmailNotifier(c *cli.Context, acceptedLogLevels []log.Level) typeNotifier {
|
||||
n := &emailTypeNotifier{
|
||||
From: c.GlobalString("notification-email-from"),
|
||||
To: c.GlobalString("notification-email-to"),
|
||||
|
|
@ -39,6 +40,7 @@ func newEmailNotifier(c *cli.Context) typeNotifier {
|
|||
Password: c.GlobalString("notification-email-server-password"),
|
||||
Port: c.GlobalInt("notification-email-server-port"),
|
||||
tlsSkipVerify: c.GlobalBool("notification-email-server-tls-skip-verify"),
|
||||
logLevels: acceptedLogLevels,
|
||||
}
|
||||
|
||||
log.AddHook(n)
|
||||
|
|
@ -112,14 +114,7 @@ func (e *emailTypeNotifier) SendNotification() {
|
|||
}
|
||||
|
||||
func (e *emailTypeNotifier) Levels() []log.Level {
|
||||
// TODO: Make this configurable.
|
||||
return []log.Level{
|
||||
log.PanicLevel,
|
||||
log.FatalLevel,
|
||||
log.ErrorLevel,
|
||||
log.WarnLevel,
|
||||
log.InfoLevel,
|
||||
}
|
||||
return e.logLevels
|
||||
}
|
||||
|
||||
func (e *emailTypeNotifier) Fire(entry *log.Entry) error {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package notifications
|
||||
|
||||
import (
|
||||
"github.com/johntdyer/slackrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
|
@ -19,15 +20,22 @@ type Notifier struct {
|
|||
func NewNotifier(c *cli.Context) *Notifier {
|
||||
n := &Notifier{}
|
||||
|
||||
logLevel, err := log.ParseLevel(c.GlobalString("notifications-level"))
|
||||
if err != nil {
|
||||
log.Fatalf("Notifications invalid log level: %s", err.Error())
|
||||
}
|
||||
|
||||
acceptedLogLevels := slackrus.LevelThreshold(logLevel)
|
||||
|
||||
// Parse types and create notifiers.
|
||||
types := c.GlobalStringSlice("notifications")
|
||||
for _, t := range types {
|
||||
var tn typeNotifier
|
||||
switch t {
|
||||
case emailType:
|
||||
tn = newEmailNotifier(c)
|
||||
tn = newEmailNotifier(c, acceptedLogLevels)
|
||||
case slackType:
|
||||
tn = newSlackNotifier(c)
|
||||
tn = newSlackNotifier(c, acceptedLogLevels)
|
||||
default:
|
||||
log.Fatalf("Unknown notification type %q", t)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,17 +14,12 @@ 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())
|
||||
}
|
||||
|
||||
func newSlackNotifier(c *cli.Context, acceptedLogLevels []log.Level) typeNotifier {
|
||||
n := &slackTypeNotifier{
|
||||
SlackrusHook: slackrus.SlackrusHook{
|
||||
HookURL: c.GlobalString("notification-slack-hook-url"),
|
||||
Username: c.GlobalString("notification-slack-identifier"),
|
||||
AcceptedLevels: slackrus.LevelThreshold(logLevel),
|
||||
AcceptedLevels: acceptedLogLevels,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue