New: Health events for Webhooks

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/5215/head
Mark McDowall 4 years ago committed by Qstick
parent a9a0d47f9f
commit 3bc4231640

@ -26,7 +26,7 @@ namespace NzbDrone.Core.Notifications.Webhook
var payload = new WebhookGrabPayload var payload = new WebhookGrabPayload
{ {
EventType = "Grab", EventType = WebhookEventType.Grab,
Movie = new WebhookMovie(message.Movie), Movie = new WebhookMovie(message.Movie),
RemoteMovie = new WebhookRemoteMovie(remoteMovie), RemoteMovie = new WebhookRemoteMovie(remoteMovie),
Release = new WebhookRelease(quality, remoteMovie), Release = new WebhookRelease(quality, remoteMovie),
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Notifications.Webhook
var payload = new WebhookImportPayload var payload = new WebhookImportPayload
{ {
EventType = "Download", EventType = WebhookEventType.Download,
Movie = new WebhookMovie(message.Movie), Movie = new WebhookMovie(message.Movie),
RemoteMovie = new WebhookRemoteMovie(message.Movie), RemoteMovie = new WebhookRemoteMovie(message.Movie),
MovieFile = new WebhookMovieFile(movieFile), MovieFile = new WebhookMovieFile(movieFile),
@ -66,15 +66,29 @@ namespace NzbDrone.Core.Notifications.Webhook
public override void OnMovieRename(Movie movie) public override void OnMovieRename(Movie movie)
{ {
var payload = new WebhookPayload var payload = new WebhookRenamePayload
{ {
EventType = "Rename", EventType = WebhookEventType.Rename,
Movie = new WebhookMovie(movie) Movie = new WebhookMovie(movie)
}; };
_proxy.SendWebhook(payload, Settings); _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 string Name => "Webhook";
public override ValidationResult Test() public override ValidationResult Test()
@ -92,7 +106,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
var payload = new WebhookGrabPayload var payload = new WebhookGrabPayload
{ {
EventType = "Test", EventType = WebhookEventType.Test,
Movie = new WebhookMovie Movie = new WebhookMovie
{ {
Id = 1, Id = 1,

@ -0,0 +1,17 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
namespace NzbDrone.Core.Notifications.Webhook
{
// TODO: In v4 this will likely be changed to the default camel case.
[JsonConverter(typeof(StringEnumConverter), converterParameters: typeof(DefaultNamingStrategy))]
public enum WebhookEventType
{
Test,
Grab,
Download,
Rename,
Health
}
}

@ -2,6 +2,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
public class WebhookGrabPayload : WebhookPayload public class WebhookGrabPayload : WebhookPayload
{ {
public WebhookMovie Movie { get; set; }
public WebhookRemoteMovie RemoteMovie { get; set; } public WebhookRemoteMovie RemoteMovie { get; set; }
public WebhookRelease Release { get; set; } public WebhookRelease Release { get; set; }
public string DownloadClient { get; set; } public string DownloadClient { get; set; }

@ -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; }
}
}

@ -4,6 +4,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
public class WebhookImportPayload : WebhookPayload public class WebhookImportPayload : WebhookPayload
{ {
public WebhookMovie Movie { get; set; }
public WebhookRemoteMovie RemoteMovie { get; set; } public WebhookRemoteMovie RemoteMovie { get; set; }
public WebhookMovieFile MovieFile { get; set; } public WebhookMovieFile MovieFile { get; set; }
public bool IsUpgrade { get; set; } public bool IsUpgrade { get; set; }

@ -2,7 +2,6 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
public class WebhookPayload public class WebhookPayload
{ {
public string EventType { get; set; } public WebhookEventType EventType { get; set; }
public WebhookMovie Movie { get; set; }
} }
} }

@ -0,0 +1,7 @@
namespace NzbDrone.Core.Notifications.Webhook
{
public class WebhookRenamePayload : WebhookPayload
{
public WebhookMovie Movie { get; set; }
}
}
Loading…
Cancel
Save