From ee32829cdb90b9554f4dbfad185eebc2451cb5de 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 | 24 +++++++++++++++---- .../Notifications/Webhook/WebhookEventType.cs | 11 +++++++++ .../Webhook/WebhookGrabPayload.cs | 1 + .../Webhook/WebhookHealthPayload.cs | 12 ++++++++++ .../Webhook/WebhookImportPayload.cs | 1 + .../Notifications/Webhook/WebhookPayload.cs | 3 +-- .../Webhook/WebhookRenamePayload.cs | 7 ++++++ 7 files changed, 52 insertions(+), 7 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 diff --git a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs index 9e5eef152..6ae6973d6 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Notifications.Webhook var payload = new WebhookGrabPayload { - EventType = "Grab", + EventType = WebhookEventType.Grab, Series = new WebhookSeries(message.Series), Episodes = remoteEpisode.Episodes.ConvertAll(x => new WebhookEpisode(x)), Release = new WebhookRelease(quality, remoteEpisode), @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Notifications.Webhook var payload = new WebhookImportPayload { - EventType = "Download", + EventType = WebhookEventType.Download, Series = new WebhookSeries(message.Series), Episodes = episodeFile.Episodes.Value.ConvertAll(x => new WebhookEpisode(x)), EpisodeFile = new WebhookEpisodeFile(episodeFile), @@ -67,15 +67,29 @@ namespace NzbDrone.Core.Notifications.Webhook public override void OnRename(Series series) { - var payload = new WebhookPayload + var payload = new WebhookRenamePayload { - EventType = "Rename", + EventType = WebhookEventType.Rename, Series = new WebhookSeries(series) }; _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() @@ -93,7 +107,7 @@ namespace NzbDrone.Core.Notifications.Webhook { var payload = new WebhookGrabPayload { - EventType = "Test", + EventType = WebhookEventType.Test, Series = new WebhookSeries() { 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..a82f0da2c --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookEventType.cs @@ -0,0 +1,11 @@ +namespace NzbDrone.Core.Notifications.Webhook +{ + public enum WebhookEventType + { + Test, + Grab, + Download, + Rename, + Health + } +} diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookGrabPayload.cs index cb5d90abd..634317728 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 WebhookSeries Series { get; set; } public List Episodes { 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 87ba9c423..e440e445e 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 WebhookSeries Series { get; set; } public List Episodes { get; set; } public WebhookEpisodeFile EpisodeFile { 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 6dffbb714..08281a50a 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs @@ -2,7 +2,6 @@ { public class WebhookPayload { - public string EventType { get; set; } - public WebhookSeries Series { get; set; } + public WebhookEventType EventType { get; set; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs new file mode 100644 index 000000000..04dc6be5f --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookRenamePayload.cs @@ -0,0 +1,7 @@ +namespace NzbDrone.Core.Notifications.Webhook +{ + public class WebhookRenamePayload : WebhookPayload + { + public WebhookSeries Series { get; set; } + } +}