mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
parent
3bbe1bd109
commit
35490c853d
9 changed files with 375 additions and 295 deletions
|
|
@ -1,6 +1,9 @@
|
|||
package notifications
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
shoutrrrSlack "github.com/containrrr/shoutrrr/pkg/services/slack"
|
||||
t "github.com/containrrr/watchtower/pkg/types"
|
||||
"github.com/johntdyer/slackrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
|
@ -15,7 +18,12 @@ type slackTypeNotifier struct {
|
|||
slackrus.SlackrusHook
|
||||
}
|
||||
|
||||
func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
|
||||
// NewSlackNotifier is a factory function used to generate new instance of the slack notifier type
|
||||
func NewSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
|
||||
return newSlackNotifier(c, acceptedLogLevels)
|
||||
}
|
||||
|
||||
func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
|
||||
flags := c.PersistentFlags()
|
||||
|
||||
hookURL, _ := flags.GetString("notification-slack-hook-url")
|
||||
|
|
@ -23,7 +31,6 @@ func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie
|
|||
channel, _ := flags.GetString("notification-slack-channel")
|
||||
emoji, _ := flags.GetString("notification-slack-icon-emoji")
|
||||
iconURL, _ := flags.GetString("notification-slack-icon-url")
|
||||
|
||||
n := &slackTypeNotifier{
|
||||
SlackrusHook: slackrus.SlackrusHook{
|
||||
HookURL: hookURL,
|
||||
|
|
@ -34,12 +41,27 @@ func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifie
|
|||
AcceptedLevels: acceptedLogLevels,
|
||||
},
|
||||
}
|
||||
|
||||
log.AddHook(n)
|
||||
return n
|
||||
}
|
||||
|
||||
func (s *slackTypeNotifier) StartNotification() {}
|
||||
func (s *slackTypeNotifier) GetURL() string {
|
||||
rawTokens := strings.Replace(s.HookURL, "https://hooks.slack.com/services/", "", 1)
|
||||
tokens := strings.Split(rawTokens, "/")
|
||||
|
||||
conf := &shoutrrrSlack.Config{
|
||||
BotName: s.Username,
|
||||
Token: shoutrrrSlack.Token{
|
||||
A: tokens[0],
|
||||
B: tokens[1],
|
||||
C: tokens[2],
|
||||
},
|
||||
}
|
||||
|
||||
return conf.GetURL().String()
|
||||
}
|
||||
|
||||
func (s *slackTypeNotifier) StartNotification() {
|
||||
}
|
||||
|
||||
func (s *slackTypeNotifier) SendNotification() {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue