mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 14:10:12 +01:00
Adding basic (but flexible) notification system which hooks into logrus.
This only adds e-mail notifications, but others could be easily done. In many cases, adding another existing logrus hook will be sufficient.
This commit is contained in:
parent
717ca9fcaf
commit
5adb143f62
3 changed files with 199 additions and 2 deletions
46
notifications/notifier.go
Normal file
46
notifications/notifier.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package notifications
|
||||
|
||||
import (
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
type typeNotifier interface {
|
||||
StartNotification()
|
||||
SendNotification()
|
||||
}
|
||||
|
||||
type Notifier struct {
|
||||
types []typeNotifier
|
||||
}
|
||||
|
||||
func NewNotifier(c *cli.Context) *Notifier {
|
||||
n := &Notifier{}
|
||||
|
||||
// Parse types and create notifiers.
|
||||
types := c.GlobalStringSlice("notifications")
|
||||
for _, t := range types {
|
||||
var tn typeNotifier
|
||||
switch t {
|
||||
case emailType:
|
||||
tn = newEmailNotifier(c)
|
||||
default:
|
||||
log.Fatalf("Unknown notification type %q", t)
|
||||
}
|
||||
n.types = append(n.types, tn)
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *Notifier) StartNotification() {
|
||||
for _, t := range n.types {
|
||||
t.StartNotification()
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Notifier) SendNotification() {
|
||||
for _, t := range n.types {
|
||||
t.SendNotification()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue