From 5afe37e929d08497cdbf75cbed46f8fdeaaf9cd8 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 9 Oct 2020 07:38:05 -0700 Subject: [PATCH] New: Health events for Webhooks Signed-off-by: Robin Dadswell --- .../Notifications/Webhook/Webhook.cs | 38 +++++++++++++------ .../Notifications/Webhook/WebhookEventType.cs | 12 ++++++ .../Webhook/WebhookGrabPayload.cs | 1 + .../Webhook/WebhookHealthPayload.cs | 12 ++++++ .../Webhook/WebhookImportPayload.cs | 1 + .../Notifications/Webhook/WebhookPayload.cs | 3 +- .../Webhook/WebhookRenamePayload.cs | 7 ++++ .../Webhook/WebhookRetagPayload.cs | 7 ++++ 8 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookHealthPayload.cs create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs diff --git a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs index 32bc9866f..6216cc261 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -25,9 +25,9 @@ namespace NzbDrone.Core.Notifications.Webhook var payload = new WebhookGrabPayload { - EventType = "Grab", - Author = new WebhookAuthor(message.Author), - Books = remoteBook.Books.ConvertAll(x => new WebhookBook(x) + EventType = WebhookEventType.Grab, + Artist = new WebhookAuthor(message.Author), + Albums = remoteBook.Books.ConvertAll(x => new WebhookBook(x) { // TODO: Stop passing these parameters inside an album v3 Quality = quality.Quality.Name, @@ -48,7 +48,7 @@ namespace NzbDrone.Core.Notifications.Webhook var payload = new WebhookImportPayload { - EventType = "Download", + EventType = WebhookEventType.Download, Artist = new WebhookAuthor(message.Author), Book = new WebhookBook(message.Book), BookFiles = bookFiles.ConvertAll(x => new WebhookBookFile(x)), @@ -62,10 +62,10 @@ namespace NzbDrone.Core.Notifications.Webhook public override void OnRename(Author author) { - var payload = new WebhookPayload + var payload = new WebhookRenamePayload { - EventType = "Rename", - Author = new WebhookAuthor(author) + EventType = WebhookEventType.Rename, + Artist = new WebhookAuthor(author) }; _proxy.SendWebhook(payload, Settings); @@ -73,15 +73,29 @@ namespace NzbDrone.Core.Notifications.Webhook public override void OnBookRetag(BookRetagMessage message) { - var payload = new WebhookPayload + var payload = new WebhookRetagPayload { - EventType = "Retag", - Author = new WebhookAuthor(message.Author) + EventType = WebhookEventType.Retag, + Artist = new WebhookAuthor(message.Author) }; _proxy.SendWebhook(payload, Settings); } + public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) + { + var payload = new WebhookHealthPayload + { + EventType = WebhookEventType.Health, + Level = healthCheck.Type, + Message = healthCheck.Message, + Type = healthCheck.Source.Name, + WikiUrl = healthCheck.WikiUrl?.ToString() + }; + + _proxy.SendWebhook(payload, Settings); + } + public override string Name => "Webhook"; public override ValidationResult Test() @@ -99,8 +113,8 @@ namespace NzbDrone.Core.Notifications.Webhook { var payload = new WebhookGrabPayload { - EventType = "Test", - Author = new WebhookAuthor() + EventType = WebhookEventType.Test, + Artist = new WebhookAuthor() { Id = 1, Name = "Test Name", diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs new file mode 100644 index 000000000..618be74be --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs @@ -0,0 +1,12 @@ +namespace NzbDrone.Core.Notifications.Webhook +{ + public enum WebhookEventType + { + Test, + Grab, + Download, + Rename, + Health, + Retag + } +} diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs index c0824a6f0..5990afce7 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs @@ -4,6 +4,7 @@ namespace NzbDrone.Core.Notifications.Webhook { public class WebhookGrabPayload : WebhookPayload { + public WebhookAuthor Author { get; set; } public List Books { get; set; } public WebhookRelease Release { get; set; } public string DownloadClient { get; set; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookHealthPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookHealthPayload.cs new file mode 100644 index 000000000..0fb4f9a03 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookHealthPayload.cs @@ -0,0 +1,12 @@ +using NzbDrone.Core.HealthCheck; + +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookHealthPayload : WebhookPayload + { + public HealthCheckResult Level { get; set; } + public string Message { get; set; } + public string Type { get; set; } + public string WikiUrl { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs index bf9c46502..aaf779e73 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookImportPayload.cs @@ -4,6 +4,7 @@ namespace NzbDrone.Core.Notifications.Webhook { public class WebhookImportPayload : WebhookPayload { + public WebhookAuthor Author { get; set; } public WebhookBook Book { get; set; } public List BookFiles { get; set; } public bool IsUpgrade { get; set; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs index d54d00ea2..4b63a748e 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs @@ -2,7 +2,6 @@ namespace NzbDrone.Core.Notifications.Webhook { public class WebhookPayload { - public string EventType { get; set; } - public WebhookAuthor Author { get; set; } + public WebhookEventType EventType { get; set; } } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs new file mode 100644 index 000000000..94e4e5cc3 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs @@ -0,0 +1,7 @@ +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookRenamePayload : WebhookPayload + { + public WebhookArtist Artist { get; set; } + } +} diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs new file mode 100644 index 000000000..b969060da --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRetagPayload.cs @@ -0,0 +1,7 @@ +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookRetagPayload : WebhookPayload + { + public WebhookArtist Artist { get; set; } + } +}