watchtower/pkg/notifications/slack.go

45 lines
1.1 KiB
Go
Raw Normal View History

2017-11-27 12:04:08 +01:00
package notifications
import (
2019-07-21 22:22:30 +02:00
t "github.com/containrrr/watchtower/pkg/types"
2017-11-27 12:04:08 +01:00
"github.com/johntdyer/slackrus"
log "github.com/sirupsen/logrus"
2019-06-22 22:04:36 +02:00
"github.com/spf13/cobra"
2017-11-27 12:04:08 +01:00
)
const (
slackType = "slack"
)
type slackTypeNotifier struct {
slackrus.SlackrusHook
}
func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
2019-06-22 22:04:36 +02:00
flags := c.PersistentFlags()
2019-07-21 22:22:30 +02:00
hookURL, _ := flags.GetString("notification-slack-hook-url")
2019-06-22 22:04:36 +02:00
userName, _ := flags.GetString("notification-slack-identifier")
2019-07-21 22:22:30 +02:00
channel, _ := flags.GetString("notification-slack-channel")
emoji, _ := flags.GetString("notification-slack-icon-emoji")
iconURL, _ := flags.GetString("notification-slack-icon-url")
2019-06-22 22:04:36 +02:00
2017-11-27 12:04:08 +01:00
n := &slackTypeNotifier{
SlackrusHook: slackrus.SlackrusHook{
2019-06-23 00:32:50 +02:00
HookURL: hookURL,
2019-06-22 22:04:36 +02:00
Username: userName,
Channel: channel,
IconEmoji: emoji,
2019-06-23 00:32:50 +02:00
IconURL: iconURL,
AcceptedLevels: acceptedLogLevels,
2017-11-27 12:04:08 +01:00
},
}
log.AddHook(n)
return n
}
func (s *slackTypeNotifier) StartNotification() {}
func (s *slackTypeNotifier) SendNotification() {}