mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00

This only adds e-mail notifications, but others could be easily done. In many cases, adding another existing logrus hook will be sufficient.
46 lines
783 B
Go
46 lines
783 B
Go
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()
|
|
}
|
|
}
|