New: Send additional information with Webhook and Custom Scripts

(cherry picked from commit e5d6e569cf05cbe431e7ffa98569017d5243d848)

Closes #3069
pull/3128/head
Devin Buhl 2 years ago committed by Bogdan
parent dc5a5240be
commit 9279ca9245

@ -8,6 +8,7 @@ using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Processes;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.HealthCheck;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Music;
@ -18,12 +19,20 @@ namespace NzbDrone.Core.Notifications.CustomScript
{
public class CustomScript : NotificationBase<CustomScriptSettings>
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IConfigService _configService;
private readonly IDiskProvider _diskProvider;
private readonly IProcessProvider _processProvider;
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;
_processProvider = processProvider;
_logger = logger;
@ -43,6 +52,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "Grab");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Artist_Id", artist.Id.ToString());
environmentVariables.Add("Lidarr_Artist_Name", artist.Metadata.Value.Name);
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId);
@ -50,6 +61,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Lidarr_Release_AlbumCount", remoteAlbum.Albums.Count.ToString());
environmentVariables.Add("Lidarr_Release_AlbumReleaseDates", string.Join(",", remoteAlbum.Albums.Select(e => e.ReleaseDate)));
environmentVariables.Add("Lidarr_Release_AlbumTitles", string.Join("|", remoteAlbum.Albums.Select(e => e.Title)));
environmentVariables.Add("Lidarr_Release_AlbumOverviews", string.Join("|", remoteAlbum.Albums.Select(e => e.Overview)));
environmentVariables.Add("Lidarr_Release_AlbumMBIds", string.Join("|", remoteAlbum.Albums.Select(e => e.ForeignAlbumId)));
environmentVariables.Add("Lidarr_Release_Title", remoteAlbum.Release.Title);
environmentVariables.Add("Lidarr_Release_Indexer", remoteAlbum.Release.Indexer ?? string.Empty);
@ -72,6 +84,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "AlbumDownload");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Artist_Id", artist.Id.ToString());
environmentVariables.Add("Lidarr_Artist_Name", artist.Metadata.Value.Name);
environmentVariables.Add("Lidarr_Artist_Path", artist.Path);
@ -79,6 +93,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
environmentVariables.Add("Lidarr_Album_Id", album.Id.ToString());
environmentVariables.Add("Lidarr_Album_Title", album.Title);
environmentVariables.Add("Lidarr_Album_Overview", album.Overview);
environmentVariables.Add("Lidarr_Album_MBId", album.ForeignAlbumId);
environmentVariables.Add("Lidarr_AlbumRelease_MBId", release.ForeignReleaseId);
environmentVariables.Add("Lidarr_Album_ReleaseDate", album.ReleaseDate.ToString());
@ -105,6 +120,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "Rename");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Artist_Id", artist.Id.ToString());
environmentVariables.Add("Lidarr_Artist_Name", artist.Metadata.Value.Name);
environmentVariables.Add("Lidarr_Artist_Path", artist.Path);
@ -126,6 +143,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "TrackRetag");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Artist_Id", artist.Id.ToString());
environmentVariables.Add("Lidarr_Artist_Name", artist.Metadata.Value.Name);
environmentVariables.Add("Lidarr_Artist_Path", artist.Path);
@ -133,6 +152,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
environmentVariables.Add("Lidarr_Album_Id", album.Id.ToString());
environmentVariables.Add("Lidarr_Album_Title", album.Title);
environmentVariables.Add("Lidarr_Album_Overview", album.Overview);
environmentVariables.Add("Lidarr_Album_MBId", album.ForeignAlbumId);
environmentVariables.Add("Lidarr_AlbumRelease_MBId", release.ForeignReleaseId);
environmentVariables.Add("Lidarr_Album_ReleaseDate", album.ReleaseDate.ToString());
@ -159,6 +179,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "AlbumDeleted");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Artist_Id", artist.Id.ToString());
environmentVariables.Add("Lidarr_Artist_Name", artist.Metadata.Value.Name);
environmentVariables.Add("Lidarr_Artist_Path", artist.Path);
@ -166,6 +188,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
environmentVariables.Add("Lidarr_Album_Id", album.Id.ToString());
environmentVariables.Add("Lidarr_Album_Title", album.Title);
environmentVariables.Add("Lidarr_Album_Overview", album.Overview);
environmentVariables.Add("Lidarr_Album_MBId", album.ForeignAlbumId);
environmentVariables.Add("Lidarr_Album_ReleaseDate", album.ReleaseDate.ToString());
environmentVariables.Add("Lidarr_Artist_DeletedFiles", deleteMessage.DeletedFiles.ToString());
@ -179,6 +202,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "ArtistDeleted");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Artist_Id", artist.Id.ToString());
environmentVariables.Add("Lidarr_Artist_Title", artist.Metadata.Value.Name);
environmentVariables.Add("Lidarr_Artist_Path", artist.Path);
@ -194,6 +219,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "HealthIssue");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Health_Issue_Level", Enum.GetName(typeof(HealthCheckResult), healthCheck.Type));
environmentVariables.Add("Lidarr_Health_Issue_Message", healthCheck.Message);
environmentVariables.Add("Lidarr_Health_Issue_Type", healthCheck.Source.Name);
@ -207,6 +234,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "ApplicationUpdate");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Lidarr_Update_Message", updateMessage.Message);
environmentVariables.Add("Lidarr_Update_NewVersion", updateMessage.NewVersion.ToString());
environmentVariables.Add("Lidarr_Update_PreviousVersion", updateMessage.PreviousVersion.ToString());
@ -237,6 +266,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
{
var environmentVariables = new StringDictionary();
environmentVariables.Add("Lidarr_EventType", "Test");
environmentVariables.Add("Lidarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Lidarr_ApplicationUrl", _configService.ApplicationUrl);
var processOutput = ExecuteScript(environmentVariables);

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

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
@ -13,8 +12,8 @@ namespace NzbDrone.Core.Notifications.Webhook
{
private readonly IWebhookProxy _proxy;
public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider)
: base(configFileProvider)
public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService)
: base(configFileProvider, configService)
{
_proxy = proxy;
}

@ -3,7 +3,6 @@ using System.Linq;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Music;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Notifications.Webhook
@ -12,11 +11,12 @@ namespace NzbDrone.Core.Notifications.Webhook
where TSettings : IProviderConfig, new()
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IConfigService _configService;
protected WebhookBase(IConfigFileProvider configFileProvider)
: base()
protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService)
{
_configFileProvider = configFileProvider;
_configService = configService;
}
public WebhookGrabPayload BuildOnGrabPayload(GrabMessage message)
@ -28,6 +28,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.Grab,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
Albums = remoteAlbum.Albums.Select(x => new WebhookAlbum(x)).ToList(),
Release = new WebhookRelease(quality, remoteAlbum),
@ -45,6 +46,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.Download,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
Album = new WebhookAlbum(message.Album),
Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y))).ToList(),
@ -69,6 +71,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.DownloadFailure,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
DownloadClient = message.DownloadClient,
DownloadId = message.DownloadId,
Quality = message.Quality.Quality.Name,
@ -85,6 +88,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.ImportFailure,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y))).ToList(),
TrackFiles = trackFiles.ConvertAll(x => new WebhookTrackFile(x)),
@ -108,6 +112,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.Rename,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(artist),
RenamedTrackFiles = renamedFiles.ConvertAll(x => new WebhookRenamedTrackFile(x))
};
@ -119,6 +124,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.Retag,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
TrackFile = new WebhookTrackFile(message.TrackFile)
};
@ -130,6 +136,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.AlbumDelete,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Album = new WebhookAlbum(deleteMessage.Album),
DeletedFiles = deleteMessage.DeletedFiles
};
@ -141,6 +148,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.ArtistDelete,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(deleteMessage.Artist),
DeletedFiles = deleteMessage.DeletedFiles
};
@ -152,6 +160,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.Health,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Level = healthCheck.Type,
Message = healthCheck.Message,
Type = healthCheck.Source.Name,
@ -165,6 +174,7 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.ApplicationUpdate,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Message = updateMessage.Message,
PreviousVersion = updateMessage.PreviousVersion.ToString(),
NewVersion = updateMessage.NewVersion.ToString()
@ -177,21 +187,22 @@ namespace NzbDrone.Core.Notifications.Webhook
{
EventType = WebhookEventType.Test,
InstanceName = _configFileProvider.InstanceName,
Artist = new WebhookArtist()
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist
{
Id = 1,
Name = "Test Name",
Path = "C:\\testpath",
MBId = "aaaaa-aaa-aaaa-aaaaaa"
},
Albums = new List<WebhookAlbum>()
Albums = new List<WebhookAlbum>
{
new ()
{
new WebhookAlbum()
{
Id = 123,
Title = "Test title"
}
Id = 123,
Title = "Test title"
}
}
};
}
}

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

Loading…
Cancel
Save