From acda741b2bc2baa3223b16d662dd8a850a437008 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 --- .../Notifications/Webhook/Webhook.cs | 28 ++++++++++++++----- .../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, 62 insertions(+), 9 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 a362786b6..127f7e153 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -25,7 +25,7 @@ namespace NzbDrone.Core.Notifications.Webhook var payload = new WebhookGrabPayload { - EventType = "Grab", + EventType = WebhookEventType.Grab, Artist = new WebhookArtist(message.Artist), Albums = remoteAlbum.Albums.ConvertAll(x => new WebhookAlbum(x) { @@ -48,7 +48,7 @@ namespace NzbDrone.Core.Notifications.Webhook var payload = new WebhookImportPayload { - EventType = "Download", + EventType = WebhookEventType.Download, Artist = new WebhookArtist(message.Artist), Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y) { @@ -68,9 +68,9 @@ namespace NzbDrone.Core.Notifications.Webhook public override void OnRename(Artist artist) { - var payload = new WebhookPayload + var payload = new WebhookRenamePayload { - EventType = "Rename", + EventType = WebhookEventType.Rename, Artist = new WebhookArtist(artist) }; @@ -79,15 +79,29 @@ namespace NzbDrone.Core.Notifications.Webhook public override void OnTrackRetag(TrackRetagMessage message) { - var payload = new WebhookPayload + var payload = new WebhookRetagPayload { - EventType = "Retag", + EventType = WebhookEventType.Retag, Artist = new WebhookArtist(message.Artist) }; _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() @@ -105,7 +119,7 @@ namespace NzbDrone.Core.Notifications.Webhook { var payload = new WebhookGrabPayload { - EventType = "Test", + EventType = WebhookEventType.Test, Artist = new WebhookArtist() { Id = 1, 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 af26b5560..27a5ca4a7 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 WebhookArtist Artist { get; set; } public List Albums { 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 5e367ce7f..172ff2e43 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 WebhookArtist Artist { get; set; } public List Tracks { get; set; } public List TrackFiles { 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 3beff4105..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 WebhookArtist Artist { 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; } + } +}