cherrypick notification changes from #450 (#745)

This commit is contained in:
Simon Aronsson 2021-01-06 20:06:56 +01:00 committed by GitHub
parent 3bbe1bd109
commit 35490c853d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 375 additions and 295 deletions

View file

@ -35,8 +35,17 @@ type shoutrrrTypeNotifier struct {
func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
flags := c.PersistentFlags()
urls, _ := flags.GetStringArray("notification-url")
template := getShoutrrrTemplate(c)
return createSender(urls, acceptedLogLevels, template)
}
func newShoutrrrNotifierFromURL(c *cobra.Command, url string, levels []log.Level) t.Notifier {
template := getShoutrrrTemplate(c)
return createSender([]string{url}, levels, template)
}
func createSender(urls []string, levels []log.Level, template *template.Template) t.Notifier {
r, err := shoutrrr.CreateSender(urls...)
if err != nil {
log.Fatalf("Failed to initialize Shoutrrr notifications: %s\n", err.Error())
@ -45,10 +54,10 @@ func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Noti
n := &shoutrrrTypeNotifier{
Urls: urls,
Router: r,
logLevels: acceptedLogLevels,
template: getShoutrrrTemplate(c),
messages: make(chan string, 1),
done: make(chan bool),
logLevels: levels,
template: template,
}
log.AddHook(n)