2018-03-13 08:39:54 +02:00
|
|
|
package notifications
|
|
|
|
|
|
|
|
import (
|
2021-01-06 21:06:56 +02:00
|
|
|
"strings"
|
2018-03-13 08:39:54 +02:00
|
|
|
|
2021-01-06 21:06:56 +02:00
|
|
|
shoutrrrTeams "github.com/containrrr/shoutrrr/pkg/services/teams"
|
2019-07-21 19:58:19 +02:00
|
|
|
t "github.com/containrrr/watchtower/pkg/types"
|
2018-03-13 08:39:54 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-01-06 21:06:56 +02:00
|
|
|
"github.com/spf13/cobra"
|
2018-03-13 08:39:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
msTeamsType = "msteams"
|
|
|
|
)
|
|
|
|
|
|
|
|
type msTeamsTypeNotifier struct {
|
|
|
|
webHookURL string
|
|
|
|
levels []log.Level
|
|
|
|
data bool
|
|
|
|
}
|
|
|
|
|
2021-01-06 21:06:56 +02:00
|
|
|
// NewMsTeamsNotifier is a factory method creating a new teams notifier instance
|
|
|
|
func NewMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
|
|
|
|
return newMsTeamsNotifier(cmd, acceptedLogLevels)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.ConvertableNotifier {
|
2018-03-13 08:39:54 +02:00
|
|
|
|
2020-12-22 00:08:23 +02:00
|
|
|
flags := cmd.PersistentFlags()
|
|
|
|
|
|
|
|
webHookURL, _ := flags.GetString("notification-msteams-hook")
|
2018-03-13 08:39:54 +02:00
|
|
|
if len(webHookURL) <= 0 {
|
|
|
|
log.Fatal("Required argument --notification-msteams-hook(cli) or WATCHTOWER_NOTIFICATION_MSTEAMS_HOOK_URL(env) is empty.")
|
|
|
|
}
|
|
|
|
|
2020-12-22 00:08:23 +02:00
|
|
|
withData, _ := flags.GetBool("notification-msteams-data")
|
2018-03-13 08:39:54 +02:00
|
|
|
n := &msTeamsTypeNotifier{
|
|
|
|
levels: acceptedLogLevels,
|
|
|
|
webHookURL: webHookURL,
|
2019-06-22 22:04:36 +02:00
|
|
|
data: withData,
|
2018-03-13 08:39:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
2021-01-06 21:06:56 +02:00
|
|
|
func (n *msTeamsTypeNotifier) GetURL() string {
|
2018-03-13 08:39:54 +02:00
|
|
|
|
2021-01-06 21:06:56 +02:00
|
|
|
baseURL := "https://outlook.office.com/webhook/"
|
2018-03-13 08:39:54 +02:00
|
|
|
|
2021-01-06 21:06:56 +02:00
|
|
|
path := strings.Replace(n.webHookURL, baseURL, "", 1)
|
|
|
|
rawToken := strings.Replace(path, "/IncomingWebhook", "", 1)
|
|
|
|
token := strings.Split(rawToken, "/")
|
|
|
|
config := &shoutrrrTeams.Config{
|
|
|
|
Token: shoutrrrTeams.Token{
|
|
|
|
A: token[0],
|
|
|
|
B: token[1],
|
|
|
|
C: token[2],
|
|
|
|
},
|
|
|
|
}
|
2018-03-13 08:39:54 +02:00
|
|
|
|
2021-01-06 21:06:56 +02:00
|
|
|
return config.GetURL().String()
|
2018-03-13 08:39:54 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 21:06:56 +02:00
|
|
|
func (n *msTeamsTypeNotifier) StartNotification() {}
|
|
|
|
func (n *msTeamsTypeNotifier) SendNotification() {}
|
2021-01-06 23:28:32 +02:00
|
|
|
func (n *msTeamsTypeNotifier) Close() {}
|
2021-01-06 21:06:56 +02:00
|
|
|
func (n *msTeamsTypeNotifier) Levels() []log.Level { return nil }
|
|
|
|
func (n *msTeamsTypeNotifier) Fire(entry *log.Entry) error { return nil }
|