|
|
@ -3,6 +3,7 @@ package notifications
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"github.com/containrrr/shoutrrr"
|
|
|
|
"github.com/containrrr/shoutrrr"
|
|
|
|
|
|
|
|
"github.com/containrrr/shoutrrr/pkg/router"
|
|
|
|
t "github.com/containrrr/watchtower/pkg/types"
|
|
|
|
t "github.com/containrrr/watchtower/pkg/types"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
@ -15,6 +16,7 @@ const (
|
|
|
|
// Implements Notifier, logrus.Hook
|
|
|
|
// Implements Notifier, logrus.Hook
|
|
|
|
type shoutrrrTypeNotifier struct {
|
|
|
|
type shoutrrrTypeNotifier struct {
|
|
|
|
Urls []string
|
|
|
|
Urls []string
|
|
|
|
|
|
|
|
Router *router.ServiceRouter
|
|
|
|
entries []*log.Entry
|
|
|
|
entries []*log.Entry
|
|
|
|
logLevels []log.Level
|
|
|
|
logLevels []log.Level
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -23,9 +25,11 @@ func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Noti
|
|
|
|
flags := c.PersistentFlags()
|
|
|
|
flags := c.PersistentFlags()
|
|
|
|
|
|
|
|
|
|
|
|
urls, _ := flags.GetStringArray("notification-url")
|
|
|
|
urls, _ := flags.GetStringArray("notification-url")
|
|
|
|
|
|
|
|
r, _ := shoutrrr.CreateSender(urls...)
|
|
|
|
|
|
|
|
|
|
|
|
n := &shoutrrrTypeNotifier{
|
|
|
|
n := &shoutrrrTypeNotifier{
|
|
|
|
Urls: urls,
|
|
|
|
Urls: urls,
|
|
|
|
|
|
|
|
Router: r,
|
|
|
|
logLevels: acceptedLogLevels,
|
|
|
|
logLevels: acceptedLogLevels,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -48,8 +52,7 @@ func (e *shoutrrrTypeNotifier) sendEntries(entries []*log.Entry) {
|
|
|
|
// Do the sending in a separate goroutine so we don't block the main process.
|
|
|
|
// Do the sending in a separate goroutine so we don't block the main process.
|
|
|
|
msg := e.buildMessage(entries)
|
|
|
|
msg := e.buildMessage(entries)
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
router, _ := shoutrrr.CreateSender(e.Urls...)
|
|
|
|
errs := e.Router.Send(msg, nil)
|
|
|
|
errs := router.Send(msg, nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i, err := range errs {
|
|
|
|
for i, err := range errs {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|