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"
|
2020-12-21 15:17:45 +01:00
|
|
|
"github.com/spf13/viper"
|
2017-11-27 12:04:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
slackType = "slack"
|
|
|
|
)
|
|
|
|
|
|
|
|
type slackTypeNotifier struct {
|
|
|
|
slackrus.SlackrusHook
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:17:45 +01:00
|
|
|
func newSlackNotifier(_ *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
|
2019-06-22 22:04:36 +02:00
|
|
|
|
2020-12-21 15:17:45 +01:00
|
|
|
hookURL := viper.GetString("notification-slack-hook-url")
|
|
|
|
userName := viper.GetString("notification-slack-identifier")
|
|
|
|
channel := viper.GetString("notification-slack-channel")
|
|
|
|
emoji := viper.GetString("notification-slack-icon-emoji")
|
|
|
|
iconURL := viper.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,
|
2018-03-02 13:08:40 +01:00
|
|
|
AcceptedLevels: acceptedLogLevels,
|
2017-11-27 12:04:08 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
log.AddHook(n)
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *slackTypeNotifier) StartNotification() {}
|
|
|
|
|
|
|
|
func (s *slackTypeNotifier) SendNotification() {}
|
2020-08-08 22:55:51 +02:00
|
|
|
|
|
|
|
func (s *slackTypeNotifier) Close() {}
|