diff --git a/pkg/notify/init/init.go b/pkg/notify/init/init.go index 52b0ac67..ca2507a0 100644 --- a/pkg/notify/init/init.go +++ b/pkg/notify/init/init.go @@ -11,7 +11,6 @@ import ( "github.com/ovh/utask/pkg/notify" "github.com/ovh/utask/pkg/notify/opsgenie" "github.com/ovh/utask/pkg/notify/slack" - "github.com/ovh/utask/pkg/notify/tat" "github.com/ovh/utask/pkg/notify/webhook" ) @@ -51,22 +50,6 @@ func Init(store *configstore.Store) error { } notify.RegisterSender(name, ogns, ncfg.DefaultNotificationStrategy, ncfg.TemplateNotificationStrategies) - case tat.Type: - f := utask.NotifyBackendTat{} - if err := json.Unmarshal(ncfg.Config, &f); err != nil { - return fmt.Errorf("%s: %s, %s: %s", errRetrieveCfg, ncfg.Type, name, err) - } - tn, err := tat.NewTatNotificationSender( - f.URL, - f.Username, - f.Password, - f.Topic, - ) - if err != nil { - return fmt.Errorf("failed to instantiate tat notification sender: %s", err) - } - notify.RegisterSender(name, tn, ncfg.DefaultNotificationStrategy, ncfg.TemplateNotificationStrategies) - case slack.Type: f := utask.NotifyBackendSlack{} if err := json.Unmarshal(ncfg.Config, &f); err != nil { diff --git a/pkg/notify/tat/tat.go b/pkg/notify/tat/tat.go deleted file mode 100644 index ee307aed..00000000 --- a/pkg/notify/tat/tat.go +++ /dev/null @@ -1,106 +0,0 @@ -package tat - -import ( - "fmt" - - tatlib "github.com/ovh/tat" - - "github.com/ovh/utask/pkg/notify" -) - -const ( - // Type represents Tat as notify backend - Type string = "tat" -) - -var labelColors = []string{ - "#2E0927", - "#FF8C00", - "#04756F", - "#D90000", - "#FF2D00", - "#0080FF", -} - -// NotificationSender is a notify.NotificationSender implementation -// capable of sending formatted notifications over TaT (github.com/ovh/tat) -type NotificationSender struct { - tatURL string - tatUser string - tatPassword string - tatTopic string -} - -// NewTatNotificationSender instantiates a NotificationSender -func NewTatNotificationSender(url, user, pass, topic string) (*NotificationSender, error) { - tn := &NotificationSender{ - tatURL: url, - tatUser: user, - tatPassword: pass, - tatTopic: topic, - } - _, err := tn.spawnTatClient() - if err != nil { - return nil, err - } - return tn, nil -} - -// Send dispatches a notify.Message to TaT -func (tn *NotificationSender) Send(m *notify.Message, name string) { - client, err := tn.spawnTatClient() - if err != nil { - notify.WrappedSendError(err, m, Type, name) - return - } - - labels := formatSendRequest(m, name) - - _, err = client.MessageAdd( - tatlib.MessageJSON{ - Text: m.MainMessage, - Labels: labels, - Topic: tn.tatTopic, - }, - ) - if err != nil { - notify.WrappedSendError(err, m, Type, name) - return - } - // TODO create message for task creation - // TODO update message afterwards, selecting on #id:xxx -} - -func (tn *NotificationSender) spawnTatClient() (*tatlib.Client, error) { - return tatlib.NewClient(tatlib.Options{ - URL: tn.tatURL, - Username: tn.tatUser, - Password: tn.tatPassword, - }) -} - -func taskLabels(fields []string) []tatlib.Label { - l := make([]tatlib.Label, 0) - for i, f := range fields { - l = append(l, tatlib.Label{ - Text: f, - Color: labelColors[i%len(labelColors)], - }) - } - return l -} - -func formatSendRequest(m *notify.Message, name string) []tatlib.Label { - labels := []string{} - - for key, value := range m.Fields { - if len(value) > 0 { - labels = append(labels, - fmt.Sprintf("%s:%s", key, value)) - } - } - - labels = append(labels, fmt.Sprintf("backend_name:%s", name)) - - return taskLabels(labels) -}