New: Send additional information with Webhook and Custom Scripts

Closes #7730

Co-Authored-By: Devin Buhl <onedr0p@users.noreply.github.com>
pull/7983/head
Qstick 2 years ago
parent 66ddd08684
commit 2327b72558

@ -8,6 +8,7 @@ using NLog;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.HealthCheck; using NzbDrone.Core.HealthCheck;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.MediaInfo; using NzbDrone.Core.MediaFiles.MediaInfo;
@ -19,12 +20,20 @@ namespace NzbDrone.Core.Notifications.CustomScript
{ {
public class CustomScript : NotificationBase<CustomScriptSettings> public class CustomScript : NotificationBase<CustomScriptSettings>
{ {
private readonly IConfigFileProvider _configFileProvider;
private readonly IConfigService _configService;
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly IProcessProvider _processProvider; private readonly IProcessProvider _processProvider;
private readonly Logger _logger; private readonly Logger _logger;
public CustomScript(IDiskProvider diskProvider, IProcessProvider processProvider, Logger logger) public CustomScript(IConfigFileProvider configFileProvider,
IConfigService configService,
IDiskProvider diskProvider,
IProcessProvider processProvider,
Logger logger)
{ {
_configFileProvider = configFileProvider;
_configService = configService;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_processProvider = processProvider; _processProvider = processProvider;
_logger = logger; _logger = logger;
@ -44,6 +53,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "Grab"); environmentVariables.Add("Radarr_EventType", "Grab");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString());
environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title); environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title);
environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString()); environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString());
@ -75,6 +86,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "Download"); environmentVariables.Add("Radarr_EventType", "Download");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_IsUpgrade", message.OldMovieFiles.Any().ToString()); environmentVariables.Add("Radarr_IsUpgrade", message.OldMovieFiles.Any().ToString());
environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString());
environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title); environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title);
@ -121,6 +134,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "Rename"); environmentVariables.Add("Radarr_EventType", "Rename");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString());
environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title); environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title);
environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString()); environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString());
@ -143,6 +158,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "MovieAdded"); environmentVariables.Add("Radarr_EventType", "MovieAdded");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString());
environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title); environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title);
environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString()); environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString());
@ -162,6 +179,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "MovieFileDelete"); environmentVariables.Add("Radarr_EventType", "MovieFileDelete");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_MovieFile_DeleteReason", deleteMessage.Reason.ToString()); environmentVariables.Add("Radarr_MovieFile_DeleteReason", deleteMessage.Reason.ToString());
environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString());
environmentVariables.Add("Radarr_Movie_Title", movie.Title); environmentVariables.Add("Radarr_Movie_Title", movie.Title);
@ -187,6 +206,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "MovieDelete"); environmentVariables.Add("Radarr_EventType", "MovieDelete");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString());
environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title); environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title);
environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString()); environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString());
@ -208,6 +229,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "HealthIssue"); environmentVariables.Add("Radarr_EventType", "HealthIssue");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_Health_Issue_Level", Enum.GetName(typeof(HealthCheckResult), healthCheck.Type)); environmentVariables.Add("Radarr_Health_Issue_Level", Enum.GetName(typeof(HealthCheckResult), healthCheck.Type));
environmentVariables.Add("Radarr_Health_Issue_Message", healthCheck.Message); environmentVariables.Add("Radarr_Health_Issue_Message", healthCheck.Message);
environmentVariables.Add("Radarr_Health_Issue_Type", healthCheck.Source.Name); environmentVariables.Add("Radarr_Health_Issue_Type", healthCheck.Source.Name);
@ -221,6 +244,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary();
environmentVariables.Add("Radarr_EventType", "ApplicationUpdate"); environmentVariables.Add("Radarr_EventType", "ApplicationUpdate");
environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Radarr_Update_Message", updateMessage.Message); environmentVariables.Add("Radarr_Update_Message", updateMessage.Message);
environmentVariables.Add("Radarr_Update_NewVersion", updateMessage.NewVersion.ToString()); environmentVariables.Add("Radarr_Update_NewVersion", updateMessage.NewVersion.ToString());
environmentVariables.Add("Radarr_Update_PreviousVersion", updateMessage.PreviousVersion.ToString()); environmentVariables.Add("Radarr_Update_PreviousVersion", updateMessage.PreviousVersion.ToString());
@ -249,8 +274,12 @@ namespace NzbDrone.Core.Notifications.CustomScript
{ {
try try
{ {
var environmentVariables = new StringDictionary(); var environmentVariables = new StringDictionary
environmentVariables.Add("Radarr_EventType", "Test"); {
{ "Radarr_EventType", "Test" },
{ "Radarr_InstanceName", _configFileProvider.InstanceName },
{ "Radarr_ApplicationUrl", _configService.ApplicationUrl }
};
var processOutput = ExecuteScript(environmentVariables); var processOutput = ExecuteScript(environmentVariables);

@ -13,8 +13,8 @@ namespace NzbDrone.Core.Notifications.Notifiarr
{ {
private readonly INotifiarrProxy _proxy; private readonly INotifiarrProxy _proxy;
public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider) public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService)
: base(configFileProvider) : base(configFileProvider, configService)
{ {
_proxy = proxy; _proxy = proxy;
} }

@ -12,8 +12,8 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
private readonly IWebhookProxy _proxy; private readonly IWebhookProxy _proxy;
public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider) public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService)
: base(configFileProvider) : base(configFileProvider, configService)
{ {
_proxy = proxy; _proxy = proxy;
} }

@ -12,11 +12,13 @@ namespace NzbDrone.Core.Notifications.Webhook
where TSettings : IProviderConfig, new() where TSettings : IProviderConfig, new()
{ {
private readonly IConfigFileProvider _configFileProvider; private readonly IConfigFileProvider _configFileProvider;
private readonly IConfigService _configService;
protected WebhookBase(IConfigFileProvider configFileProvider) protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService)
: base() : base()
{ {
_configFileProvider = configFileProvider; _configFileProvider = configFileProvider;
_configService = configService;
} }
protected WebhookGrabPayload BuildOnGrabPayload(GrabMessage message) protected WebhookGrabPayload BuildOnGrabPayload(GrabMessage message)
@ -28,6 +30,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.Grab, EventType = WebhookEventType.Grab,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
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),
@ -45,6 +48,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.Download, EventType = WebhookEventType.Download,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
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),
@ -72,6 +76,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.MovieAdded, EventType = WebhookEventType.MovieAdded,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Movie = new WebhookMovie(movie), Movie = new WebhookMovie(movie),
AddMethod = movie.AddOptions.AddMethod AddMethod = movie.AddOptions.AddMethod
}; };
@ -83,6 +88,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.MovieFileDelete, EventType = WebhookEventType.MovieFileDelete,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Movie = new WebhookMovie(deleteMessage.Movie), Movie = new WebhookMovie(deleteMessage.Movie),
MovieFile = new WebhookMovieFile(deleteMessage.MovieFile), MovieFile = new WebhookMovieFile(deleteMessage.MovieFile),
DeleteReason = deleteMessage.Reason DeleteReason = deleteMessage.Reason
@ -95,6 +101,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.MovieDelete, EventType = WebhookEventType.MovieDelete,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Movie = new WebhookMovie(deleteMessage.Movie), Movie = new WebhookMovie(deleteMessage.Movie),
DeletedFiles = deleteMessage.DeletedFiles DeletedFiles = deleteMessage.DeletedFiles
}; };
@ -113,6 +120,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.Rename, EventType = WebhookEventType.Rename,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Movie = new WebhookMovie(movie), Movie = new WebhookMovie(movie),
RenamedMovieFiles = renamedFiles.ConvertAll(x => new WebhookRenamedMovieFile(x)) RenamedMovieFiles = renamedFiles.ConvertAll(x => new WebhookRenamedMovieFile(x))
}; };
@ -124,6 +132,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.Health, EventType = WebhookEventType.Health,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Level = healthCheck.Type, Level = healthCheck.Type,
Message = healthCheck.Message, Message = healthCheck.Message,
Type = healthCheck.Source.Name, Type = healthCheck.Source.Name,
@ -137,6 +146,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.ApplicationUpdate, EventType = WebhookEventType.ApplicationUpdate,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Message = updateMessage.Message, Message = updateMessage.Message,
PreviousVersion = updateMessage.PreviousVersion.ToString(), PreviousVersion = updateMessage.PreviousVersion.ToString(),
NewVersion = updateMessage.NewVersion.ToString() NewVersion = updateMessage.NewVersion.ToString()
@ -149,6 +159,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
EventType = WebhookEventType.Test, EventType = WebhookEventType.Test,
InstanceName = _configFileProvider.InstanceName, InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Movie = new WebhookMovie Movie = new WebhookMovie
{ {
Id = 1, Id = 1,

@ -4,5 +4,6 @@ namespace NzbDrone.Core.Notifications.Webhook
{ {
public WebhookEventType EventType { get; set; } public WebhookEventType EventType { get; set; }
public string InstanceName { get; set; } public string InstanceName { get; set; }
public string ApplicationUrl { get; set; }
} }
} }

Loading…
Cancel
Save