feat(notifications): add Notifiarr support (#464)

This commit is contained in:
ze0s 2022-09-19 15:44:31 +02:00 committed by GitHub
parent f8ace9edbe
commit 63d4c21e54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 326 additions and 18 deletions

View file

@ -2,6 +2,9 @@ package notification
import (
"context"
"time"
"golang.org/x/sync/errgroup"
"github.com/autobrr/autobrr/internal/domain"
"github.com/autobrr/autobrr/internal/logger"
@ -117,6 +120,8 @@ func (s *service) registerSenders() {
switch n.Type {
case domain.NotificationTypeDiscord:
s.senders = append(s.senders, NewDiscordSender(s.log, n))
case domain.NotificationTypeNotifiarr:
s.senders = append(s.senders, NewNotifiarrSender(s.log, n))
case domain.NotificationTypeTelegram:
s.senders = append(s.senders, NewTelegramSender(s.log, n))
}
@ -147,15 +152,106 @@ func (s *service) Send(event domain.NotificationEvent, payload domain.Notificati
func (s *service) Test(ctx context.Context, notification domain.Notification) error {
var agent domain.NotificationSender
// send test events
events := []domain.NotificationPayload{
{
Subject: "Test Notification",
Message: "autobrr goes brr!!",
Event: domain.NotificationEventTest,
Timestamp: time.Now(),
},
{
Subject: "New release!",
Message: "Best.Show.Ever.S18E21.1080p.AMZN.WEB-DL.DDP2.0.H.264-GROUP",
Event: domain.NotificationEventPushApproved,
ReleaseName: "Best.Show.Ever.S18E21.1080p.AMZN.WEB-DL.DDP2.0.H.264-GROUP",
Filter: "TV",
Indexer: "MockIndexer",
Status: domain.ReleasePushStatusApproved,
Action: "Send to qBittorrent",
ActionType: domain.ActionTypeQbittorrent,
ActionClient: "qBittorrent",
Rejections: nil,
Protocol: domain.ReleaseProtocolTorrent,
Implementation: domain.ReleaseImplementationIRC,
Timestamp: time.Now(),
},
{
Subject: "New release!",
Message: "Best.Show.Ever.S18E21.1080p.AMZN.WEB-DL.DDP2.0.H.264-GROUP",
Event: domain.NotificationEventPushRejected,
ReleaseName: "Best.Show.Ever.S18E21.1080p.AMZN.WEB-DL.DDP2.0.H.264-GROUP",
Filter: "TV",
Indexer: "MockIndexer",
Status: domain.ReleasePushStatusRejected,
Action: "Send to Sonarr",
ActionType: domain.ActionTypeSonarr,
ActionClient: "Sonarr",
Rejections: []string{"Unknown Series"},
Protocol: domain.ReleaseProtocolTorrent,
Implementation: domain.ReleaseImplementationIRC,
Timestamp: time.Now(),
},
{
Subject: "New release!",
Message: "Best.Show.Ever.S18E21.1080p.AMZN.WEB-DL.DDP2.0.H.264-GROUP",
Event: domain.NotificationEventPushError,
ReleaseName: "Best.Show.Ever.S18E21.1080p.AMZN.WEB-DL.DDP2.0.H.264-GROUP",
Filter: "TV",
Indexer: "MockIndexer",
Status: domain.ReleasePushStatusErr,
Action: "Send to Sonarr",
ActionType: domain.ActionTypeSonarr,
ActionClient: "Sonarr",
Rejections: []string{"error pushing to client"},
Protocol: domain.ReleaseProtocolTorrent,
Implementation: domain.ReleaseImplementationIRC,
Timestamp: time.Now(),
},
{
Subject: "IRC Disconnected unexpectedly",
Message: "Network: P2P-Network",
Event: domain.NotificationEventIRCDisconnected,
Timestamp: time.Now(),
},
{
Subject: "IRC Reconnected",
Message: "Network: P2P-Network",
Event: domain.NotificationEventIRCReconnected,
Timestamp: time.Now(),
},
{
Subject: "New update available!",
Message: "v1.6.0",
Event: domain.NotificationEventAppUpdateAvailable,
Timestamp: time.Now(),
},
}
switch notification.Type {
case domain.NotificationTypeDiscord:
agent = NewDiscordSender(s.log, notification)
case domain.NotificationTypeNotifiarr:
agent = NewNotifiarrSender(s.log, notification)
case domain.NotificationTypeTelegram:
agent = NewTelegramSender(s.log, notification)
}
return agent.Send(domain.NotificationEventTest, domain.NotificationPayload{
Subject: "Test Notification",
Message: "autobrr goes brr!!",
})
g, ctx := errgroup.WithContext(ctx)
for _, event := range events {
e := event
g.Go(func() error {
return agent.Send(e.Event, e)
})
time.Sleep(1 * time.Second)
}
if err := g.Wait(); err != nil {
s.log.Error().Err(err).Msgf("Something went wrong sending test notifications to %v", notification.Type)
return err
}
return nil
}