|
|
@ -1,11 +1,13 @@
|
|
|
|
package notifications
|
|
|
|
package notifications
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
ty "github.com/containrrr/watchtower/pkg/types"
|
|
|
|
ty "github.com/containrrr/watchtower/pkg/types"
|
|
|
|
"github.com/johntdyer/slackrus"
|
|
|
|
"github.com/johntdyer/slackrus"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// NewNotifier creates and returns a new Notifier, using global configuration.
|
|
|
|
// NewNotifier creates and returns a new Notifier, using global configuration.
|
|
|
@ -28,14 +30,14 @@ func NewNotifier(c *cobra.Command) ty.Notifier {
|
|
|
|
tplString, _ := f.GetString("notification-template")
|
|
|
|
tplString, _ := f.GetString("notification-template")
|
|
|
|
urls, _ := f.GetStringArray("notification-url")
|
|
|
|
urls, _ := f.GetStringArray("notification-url")
|
|
|
|
|
|
|
|
|
|
|
|
urls = AppendLegacyUrls(urls, c)
|
|
|
|
urls, delay := AppendLegacyUrls(urls, c)
|
|
|
|
|
|
|
|
|
|
|
|
title := GetTitle(c)
|
|
|
|
title := GetTitle(c)
|
|
|
|
return newShoutrrrNotifier(tplString, acceptedLogLevels, !reportTemplate, title, urls...)
|
|
|
|
return newShoutrrrNotifier(tplString, acceptedLogLevels, !reportTemplate, title, delay, urls...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// AppendLegacyUrls creates shoutrrr equivalent URLs from legacy notification flags
|
|
|
|
// AppendLegacyUrls creates shoutrrr equivalent URLs from legacy notification flags
|
|
|
|
func AppendLegacyUrls(urls []string, cmd *cobra.Command) []string {
|
|
|
|
func AppendLegacyUrls(urls []string, cmd *cobra.Command) ([]string, time.Duration) {
|
|
|
|
|
|
|
|
|
|
|
|
// Parse types and create notifiers.
|
|
|
|
// Parse types and create notifiers.
|
|
|
|
types, err := cmd.Flags().GetStringSlice("notifications")
|
|
|
|
types, err := cmd.Flags().GetStringSlice("notifications")
|
|
|
@ -43,6 +45,8 @@ func AppendLegacyUrls(urls []string, cmd *cobra.Command) []string {
|
|
|
|
log.WithError(err).Fatal("could not read notifications argument")
|
|
|
|
log.WithError(err).Fatal("could not read notifications argument")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delay := time.Duration(0)
|
|
|
|
|
|
|
|
|
|
|
|
for _, t := range types {
|
|
|
|
for _, t := range types {
|
|
|
|
|
|
|
|
|
|
|
|
var legacyNotifier ty.ConvertibleNotifier
|
|
|
|
var legacyNotifier ty.ConvertibleNotifier
|
|
|
@ -71,9 +75,13 @@ func AppendLegacyUrls(urls []string, cmd *cobra.Command) []string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
urls = append(urls, shoutrrrURL)
|
|
|
|
urls = append(urls, shoutrrrURL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if delayNotifier, ok := legacyNotifier.(ty.DelayNotifier); ok {
|
|
|
|
|
|
|
|
delay = delayNotifier.GetDelay()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.WithField("URL", shoutrrrURL).Trace("created Shoutrrr URL from legacy notifier")
|
|
|
|
log.WithField("URL", shoutrrrURL).Trace("created Shoutrrr URL from legacy notifier")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return urls
|
|
|
|
return urls, delay
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetTitle returns a common notification title with hostname appended
|
|
|
|
// GetTitle returns a common notification title with hostname appended
|
|
|
|