From 40125046fab3dfa048d88e49cfaa2925ed2bc166 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 7 May 2023 07:30:31 +0300 Subject: [PATCH 0001/1209] New: Add token authentication for ntfy.sh notifications Co-authored-by: KucharczykL (cherry picked from commit 5bb03a9ddf4d2d33976dfdc39fc70bcf56bf1b49) --- .../Notifications/Ntfy/NtfyProxy.cs | 32 ++++++++++++++----- .../Notifications/Ntfy/NtfySettings.cs | 19 ++++++----- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/Ntfy/NtfyProxy.cs b/src/NzbDrone.Core/Notifications/Ntfy/NtfyProxy.cs index c292250d6..e05dcb755 100644 --- a/src/NzbDrone.Core/Notifications/Ntfy/NtfyProxy.cs +++ b/src/NzbDrone.Core/Notifications/Ntfy/NtfyProxy.cs @@ -34,7 +34,7 @@ namespace NzbDrone.Core.Notifications.Ntfy { var error = false; - var serverUrl = settings.ServerUrl.IsNullOrWhiteSpace() ? NtfyProxy.DEFAULT_PUSH_URL : settings.ServerUrl; + var serverUrl = settings.ServerUrl.IsNullOrWhiteSpace() ? DEFAULT_PUSH_URL : settings.ServerUrl; foreach (var topic in settings.Topics) { @@ -78,10 +78,22 @@ namespace NzbDrone.Core.Notifications.Ntfy } catch (HttpException ex) { - if (ex.Response.StatusCode == HttpStatusCode.Unauthorized || ex.Response.StatusCode == HttpStatusCode.Forbidden) + if (ex.Response.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) { + if (!settings.AccessToken.IsNullOrWhiteSpace()) + { + _logger.Error(ex, "Invalid token"); + return new ValidationFailure("AccessToken", "Invalid token"); + } + + if (!settings.UserName.IsNullOrWhiteSpace() && !settings.Password.IsNullOrWhiteSpace()) + { + _logger.Error(ex, "Invalid username or password"); + return new ValidationFailure("UserName", "Invalid username or password"); + } + _logger.Error(ex, "Authorization is required"); - return new ValidationFailure("UserName", "Authorization is required"); + return new ValidationFailure("AccessToken", "Authorization is required"); } _logger.Error(ex, "Unable to send test message"); @@ -114,18 +126,22 @@ namespace NzbDrone.Core.Notifications.Ntfy requestBuilder.Headers.Add("X-Click", settings.ClickUrl); } - var request = requestBuilder.Build(); - - if (!settings.UserName.IsNullOrWhiteSpace() && !settings.Password.IsNullOrWhiteSpace()) + if (!settings.AccessToken.IsNullOrWhiteSpace()) { - request.Credentials = new BasicNetworkCredential(settings.UserName, settings.Password); + requestBuilder.Headers.Set("Authorization", $"Bearer {settings.AccessToken}"); } + else if (!settings.UserName.IsNullOrWhiteSpace() && !settings.Password.IsNullOrWhiteSpace()) + { + requestBuilder.NetworkCredential = new BasicNetworkCredential(settings.UserName, settings.Password); + } + + var request = requestBuilder.Build(); _httpClient.Execute(request); } catch (HttpException ex) { - if (ex.Response.StatusCode == HttpStatusCode.Unauthorized || ex.Response.StatusCode == HttpStatusCode.Forbidden) + if (ex.Response.StatusCode is HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) { _logger.Error(ex, "Authorization is required"); throw; diff --git a/src/NzbDrone.Core/Notifications/Ntfy/NtfySettings.cs b/src/NzbDrone.Core/Notifications/Ntfy/NtfySettings.cs index 94190458d..1c1cedec3 100644 --- a/src/NzbDrone.Core/Notifications/Ntfy/NtfySettings.cs +++ b/src/NzbDrone.Core/Notifications/Ntfy/NtfySettings.cs @@ -16,8 +16,8 @@ namespace NzbDrone.Core.Notifications.Ntfy RuleFor(c => c.Priority).InclusiveBetween(1, 5); RuleFor(c => c.ServerUrl).IsValidUrl().When(c => !c.ServerUrl.IsNullOrWhiteSpace()); RuleFor(c => c.ClickUrl).IsValidUrl().When(c => !c.ClickUrl.IsNullOrWhiteSpace()); - RuleFor(c => c.UserName).NotEmpty().When(c => !c.Password.IsNullOrWhiteSpace()); - RuleFor(c => c.Password).NotEmpty().When(c => !c.UserName.IsNullOrWhiteSpace()); + RuleFor(c => c.UserName).NotEmpty().When(c => !c.Password.IsNullOrWhiteSpace() && c.AccessToken.IsNullOrWhiteSpace()); + RuleFor(c => c.Password).NotEmpty().When(c => !c.UserName.IsNullOrWhiteSpace() && c.AccessToken.IsNullOrWhiteSpace()); RuleForEach(c => c.Topics).NotEmpty().Matches("[a-zA-Z0-9_-]+").Must(c => !InvalidTopics.Contains(c)).WithMessage("Invalid topic"); } @@ -37,22 +37,25 @@ namespace NzbDrone.Core.Notifications.Ntfy [FieldDefinition(0, Label = "Server Url", Type = FieldType.Url, HelpLink = "https://ntfy.sh/docs/install/", HelpText = "Leave blank to use public server (https://ntfy.sh)")] public string ServerUrl { get; set; } - [FieldDefinition(1, Label = "User Name", HelpText = "Optional Authorization", Privacy = PrivacyLevel.UserName)] + [FieldDefinition(1, Label = "Access Token", Type = FieldType.Password, Privacy = PrivacyLevel.ApiKey, HelpText = "Optional token-based authorization. Takes priority over username/password", HelpLink = "https://docs.ntfy.sh/config/#access-tokens")] + public string AccessToken { get; set; } + + [FieldDefinition(2, Label = "User Name", HelpText = "Optional Authorization", Privacy = PrivacyLevel.UserName)] public string UserName { get; set; } - [FieldDefinition(2, Label = "Password", Type = FieldType.Password, HelpText = "Optional Password", Privacy = PrivacyLevel.Password)] + [FieldDefinition(3, Label = "Password", Type = FieldType.Password, HelpText = "Optional Password", Privacy = PrivacyLevel.Password)] public string Password { get; set; } - [FieldDefinition(3, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(NtfyPriority))] + [FieldDefinition(4, Label = "Priority", Type = FieldType.Select, SelectOptions = typeof(NtfyPriority))] public int Priority { get; set; } - [FieldDefinition(4, Label = "Topics", HelpText = "List of Topics to send notifications to", Type = FieldType.Tag)] + [FieldDefinition(5, Label = "Topics", HelpText = "List of Topics to send notifications to", Type = FieldType.Tag)] public IEnumerable Topics { get; set; } - [FieldDefinition(5, Label = "Ntfy Tags and Emojis", Type = FieldType.Tag, HelpText = "Optional list of tags or emojis to use", HelpLink = "https://ntfy.sh/docs/emojis/")] + [FieldDefinition(6, Label = "Ntfy Tags and Emojis", Type = FieldType.Tag, HelpText = "Optional list of tags or emojis to use", HelpLink = "https://ntfy.sh/docs/emojis/")] public IEnumerable Tags { get; set; } - [FieldDefinition(6, Label = "Click Url", Type = FieldType.Url, HelpText = "Optional link when user clicks notification")] + [FieldDefinition(7, Label = "Click URL", Type = FieldType.Url, HelpText = "Optional link when user clicks notification")] public string ClickUrl { get; set; } public NzbDroneValidationResult Validate() From 008f238dda3592f23fd4f8c5c6b1c5c9e1558648 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 6 May 2023 22:34:22 -0700 Subject: [PATCH 0002/1209] New: Only add version header for API requests (cherry picked from commit 453891e620459ff38f7bc43b207004b240fc5fb8) --- src/Prowlarr.Http/Middleware/VersionMiddleware.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Prowlarr.Http/Middleware/VersionMiddleware.cs b/src/Prowlarr.Http/Middleware/VersionMiddleware.cs index f80c1c0cc..61c990f59 100644 --- a/src/Prowlarr.Http/Middleware/VersionMiddleware.cs +++ b/src/Prowlarr.Http/Middleware/VersionMiddleware.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using NzbDrone.Common.EnvironmentInfo; +using Prowlarr.Http.Extensions; namespace Prowlarr.Http.Middleware { @@ -19,7 +20,7 @@ namespace Prowlarr.Http.Middleware public async Task InvokeAsync(HttpContext context) { - if (!context.Response.Headers.ContainsKey(VERSIONHEADER)) + if (context.Request.IsApiRequest() && !context.Response.Headers.ContainsKey(VERSIONHEADER)) { context.Response.Headers.Add(VERSIONHEADER, _version); } From 92e7a38bd0a2b832d82163c5ac527ab1e23fe026 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 7 May 2023 15:54:31 +0300 Subject: [PATCH 0003/1209] Fixed: (Rarbg) Move check response by status code to parser --- .../Indexers/Definitions/Rarbg/Rarbg.cs | 23 +------------ .../Indexers/Definitions/Rarbg/RarbgParser.cs | 33 +++++++++++++------ 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs index 8089b6001..33a80dccd 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/Rarbg.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net; using System.Threading.Tasks; using System.Web; using NLog; @@ -13,7 +12,6 @@ using NzbDrone.Common.Http; using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; using NzbDrone.Core.Exceptions; -using NzbDrone.Core.Indexers.Exceptions; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; @@ -84,25 +82,6 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg return cleanReleases.Select(r => (ReleaseInfo)r.Clone()).ToList(); } - public static void CheckResponseByStatusCode(IndexerResponse response, Logger logger) - { - var responseCode = (int)response.HttpResponse.StatusCode; - - switch (responseCode) - { - case (int)HttpStatusCode.TooManyRequests: - logger.Warn("Indexer API limit reached."); - throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(2)); - case 520: - logger.Warn("Indexer API error, likely rate limited by origin server."); - throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(3)); - case (int)HttpStatusCode.OK: - break; - default: - throw new IndexerException(response, "Indexer API call returned an unexpected status code [{0}]", responseCode); - } - } - private IndexerCapabilities SetCapabilities() { var caps = new IndexerCapabilities @@ -157,7 +136,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg { var response = await base.FetchIndexerResponse(request); - CheckResponseByStatusCode(response, _logger); + ((RarbgParser)GetParser()).CheckResponseByStatusCode(response); // try and recover from token errors var jsonResponse = new HttpResponse(response.HttpResponse); diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs index dc057e40a..f612c052c 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgParser.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.EnvironmentInfo; @@ -28,7 +29,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg { var results = new List(); - Rarbg.CheckResponseByStatusCode(indexerResponse, _logger); + CheckResponseByStatusCode(indexerResponse); var jsonResponse = new HttpResponse(indexerResponse.HttpResponse); @@ -99,18 +100,30 @@ namespace NzbDrone.Core.Indexers.Definitions.Rarbg return results; } - private string GetGuid(RarbgTorrent torrent) + public void CheckResponseByStatusCode(IndexerResponse response) + { + var responseCode = (int)response.HttpResponse.StatusCode; + + switch (responseCode) + { + case (int)HttpStatusCode.TooManyRequests: + _logger.Warn("Indexer API limit reached."); + throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(2)); + case 520: + _logger.Warn("Indexer API error, likely rate limited by origin server."); + throw new TooManyRequestsException(response.HttpRequest, response.HttpResponse, TimeSpan.FromMinutes(3)); + case (int)HttpStatusCode.OK: + break; + default: + throw new IndexerException(response, "Indexer API call returned an unexpected status code [{0}]", responseCode); + } + } + + private static string GetGuid(RarbgTorrent torrent) { var match = RegexGuid.Match(torrent.download); - if (match.Success) - { - return string.Format("rarbg-{0}", match.Groups[1].Value); - } - else - { - return string.Format("rarbg-{0}", torrent.download); - } + return match.Success ? $"rarbg-{match.Groups[1].Value}" : $"rarbg-{torrent.download}"; } } } From e1d0e2c79975a10c12fc8551f5dcd4a79f1c94e7 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 7 May 2023 16:51:00 +0300 Subject: [PATCH 0004/1209] Log invalid config file exceptions Fixes #1648 --- src/NzbDrone.Host/Bootstrap.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs index 35e930b6e..5f4a750e2 100644 --- a/src/NzbDrone.Host/Bootstrap.cs +++ b/src/NzbDrone.Host/Bootstrap.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Data.SQLite; -using System.Diagnostics; using System.IO; using System.Reflection; using System.Security.Cryptography; @@ -9,8 +8,6 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using DryIoc; using DryIoc.Microsoft.DependencyInjection; -using FluentMigrator.Runner.Processors.Postgres; -using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Configuration; @@ -27,7 +24,6 @@ using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore.Extensions; -using NzbDrone.Host; using PostgresOptions = NzbDrone.Core.Datastore.PostgresOptions; namespace NzbDrone.Host @@ -240,6 +236,8 @@ namespace NzbDrone.Host } catch (InvalidDataException ex) { + Logger.Error(ex, ex.Message); + throw new InvalidConfigFileException($"{configPath} is corrupt or invalid. Please delete the config file and Prowlarr will recreate it.", ex); } } From 1a5e41d831f20858112f086d1a913f6052feb14d Mon Sep 17 00:00:00 2001 From: Weblate Date: Mon, 8 May 2023 09:36:38 +0000 Subject: [PATCH 0005/1209] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (509 of 509 strings) Co-authored-by: Havok Dan Translate-URL: https://translate.servarr.com/projects/servarr/prowlarr/pt_BR/ Translation: Servarr/Prowlarr --- src/NzbDrone.Core/Localization/Core/pt_BR.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/Localization/Core/pt_BR.json b/src/NzbDrone.Core/Localization/Core/pt_BR.json index 52349f0e0..5e0eeb51e 100644 --- a/src/NzbDrone.Core/Localization/Core/pt_BR.json +++ b/src/NzbDrone.Core/Localization/Core/pt_BR.json @@ -506,5 +506,6 @@ "TotalHostQueries": "Total de consultas do host", "TotalIndexerQueries": "Total de consultas do indexador", "SelectIndexer": "Selecionar Indexador", - "StopSelecting": "Parar Seleção" + "StopSelecting": "Parar Seleção", + "UpdateAvailable": "Nova atualização está disponível" } From 202836110ec8cd52ab7f685f2206bbd5f26557c0 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Sun, 7 Aug 2022 14:54:39 -0400 Subject: [PATCH 0006/1209] New: Add application URL to host configuration settings (cherry picked from commit 762042ba97c2ae689cee32d8e66a458f6d7a8adc) --- frontend/src/Settings/General/HostSettings.js | 16 ++++++++++++++++ src/NzbDrone.Core/Configuration/ConfigService.cs | 2 ++ .../Configuration/IConfigService.cs | 1 + src/NzbDrone.Core/Localization/Core/en.json | 4 +++- src/Prowlarr.Api.V1/Config/HostConfigResource.cs | 2 ++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/src/Settings/General/HostSettings.js b/frontend/src/Settings/General/HostSettings.js index 5445808b0..99255b0d5 100644 --- a/frontend/src/Settings/General/HostSettings.js +++ b/frontend/src/Settings/General/HostSettings.js @@ -21,6 +21,7 @@ function HostSettings(props) { port, urlBase, instanceName, + applicationUrl, enableSsl, sslPort, sslCertPath, @@ -89,6 +90,21 @@ function HostSettings(props) { /> + + {translate('ApplicationURL')} + + + + GetValueEnum("CertificateValidation", CertificateValidationType.Enabled); + public string ApplicationUrl => GetValue("ApplicationUrl", string.Empty); + private string GetValue(string key) { return GetValue(key, string.Empty); diff --git a/src/NzbDrone.Core/Configuration/IConfigService.cs b/src/NzbDrone.Core/Configuration/IConfigService.cs index 4f37b8d51..5fa2ed005 100644 --- a/src/NzbDrone.Core/Configuration/IConfigService.cs +++ b/src/NzbDrone.Core/Configuration/IConfigService.cs @@ -55,5 +55,6 @@ namespace NzbDrone.Core.Configuration bool LogIndexerResponse { get; set; } CertificateValidationType CertificateValidation { get; } + string ApplicationUrl { get; } } } diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 243d5db82..77db15c79 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -34,6 +34,8 @@ "ApplicationLongTermStatusCheckSingleClientMessage": "Applications unavailable due to failures for more than 6 hours: {0}", "ApplicationStatusCheckAllClientMessage": "All applications are unavailable due to failures", "ApplicationStatusCheckSingleClientMessage": "Applications unavailable due to failures: {0}", + "ApplicationURL": "Application URL", + "ApplicationUrlHelpText": "This application's external URL including http(s)://, port and URL base", "Applications": "Applications", "Apply": "Apply", "ApplyTags": "Apply Tags", @@ -508,4 +510,4 @@ "Yes": "Yes", "YesCancel": "Yes, Cancel", "Yesterday": "Yesterday" -} \ No newline at end of file +} diff --git a/src/Prowlarr.Api.V1/Config/HostConfigResource.cs b/src/Prowlarr.Api.V1/Config/HostConfigResource.cs index 38d132615..35f4eca84 100644 --- a/src/Prowlarr.Api.V1/Config/HostConfigResource.cs +++ b/src/Prowlarr.Api.V1/Config/HostConfigResource.cs @@ -27,6 +27,7 @@ namespace Prowlarr.Api.V1.Config public string SslCertPassword { get; set; } public string UrlBase { get; set; } public string InstanceName { get; set; } + public string ApplicationUrl { get; set; } public bool UpdateAutomatically { get; set; } public UpdateMechanism UpdateMechanism { get; set; } public string UpdateScriptPath { get; set; } @@ -86,6 +87,7 @@ namespace Prowlarr.Api.V1.Config BackupFolder = configService.BackupFolder, BackupInterval = configService.BackupInterval, BackupRetention = configService.BackupRetention, + ApplicationUrl = configService.ApplicationUrl, HistoryCleanupDays = configService.HistoryCleanupDays }; } From a753f721d1107b020661b6e2a9da827943423015 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Sun, 6 Nov 2022 11:21:28 -0500 Subject: [PATCH 0007/1209] New: Send additional information with Webhook and Custom Scripts (cherry picked from commit e5d6e569cf05cbe431e7ffa98569017d5243d848) --- .../Notifications/CustomScript/CustomScript.cs | 17 ++++++++++++++++- .../Notifications/Notifiarr/Notifiarr.cs | 4 ++-- .../Notifications/Webhook/Webhook.cs | 4 ++-- .../Notifications/Webhook/WebhookBase.cs | 11 ++++++++--- .../Notifications/Webhook/WebhookPayload.cs | 1 + 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index f7d728ca3..13dfa8478 100755 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Common.Processes; +using NzbDrone.Core.Configuration; using NzbDrone.Core.HealthCheck; using NzbDrone.Core.ThingiProvider; using NzbDrone.Core.Validation; @@ -14,12 +15,20 @@ namespace NzbDrone.Core.Notifications.CustomScript { public class CustomScript : NotificationBase { + 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; @@ -36,6 +45,8 @@ namespace NzbDrone.Core.Notifications.CustomScript var environmentVariables = new StringDictionary(); environmentVariables.Add("Prowlarr_EventType", "HealthIssue"); + environmentVariables.Add("Prowlarr_InstanceName", _configFileProvider.InstanceName); + environmentVariables.Add("Prowlarr_ApplicationUrl", _configService.ApplicationUrl); environmentVariables.Add("Prowlarr_Health_Issue_Level", Enum.GetName(typeof(HealthCheckResult), healthCheck.Type)); environmentVariables.Add("Prowlarr_Health_Issue_Message", healthCheck.Message); environmentVariables.Add("Prowlarr_Health_Issue_Type", healthCheck.Source.Name); @@ -49,6 +60,8 @@ namespace NzbDrone.Core.Notifications.CustomScript var environmentVariables = new StringDictionary(); environmentVariables.Add("Prowlarr_EventType", "ApplicationUpdate"); + environmentVariables.Add("Prowlarr_InstanceName", _configFileProvider.InstanceName); + environmentVariables.Add("Prowlarr_ApplicationUrl", _configService.ApplicationUrl); environmentVariables.Add("Prowlarr_Update_Message", updateMessage.Message); environmentVariables.Add("Prowlarr_Update_NewVersion", updateMessage.NewVersion.ToString()); environmentVariables.Add("Prowlarr_Update_PreviousVersion", updateMessage.PreviousVersion.ToString()); @@ -79,6 +92,8 @@ namespace NzbDrone.Core.Notifications.CustomScript { var environmentVariables = new StringDictionary(); environmentVariables.Add("Prowlarr_EventType", "Test"); + environmentVariables.Add("Prowlarr_InstanceName", _configFileProvider.InstanceName); + environmentVariables.Add("Prowlarr_ApplicationUrl", _configService.ApplicationUrl); var processOutput = ExecuteScript(environmentVariables); diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs index b12bd4c7d..ba6f3996b 100644 --- a/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs @@ -11,8 +11,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; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs index c22b121ca..c85d9d74d 100755 --- a/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/Webhook.cs @@ -10,8 +10,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; } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs index 06a3f61cd..9fc0341df 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs @@ -7,11 +7,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 BuildGrabPayload(GrabMessage message) @@ -20,6 +21,7 @@ namespace NzbDrone.Core.Notifications.Webhook { EventType = WebhookEventType.Grab, InstanceName = _configFileProvider.InstanceName, + ApplicationUrl = _configService.ApplicationUrl, Release = new WebhookRelease(message.Release), Trigger = message.GrabTrigger, Source = message.Source, @@ -36,6 +38,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, @@ -49,6 +52,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() @@ -60,7 +64,8 @@ namespace NzbDrone.Core.Notifications.Webhook return new WebhookPayload { EventType = WebhookEventType.Test, - InstanceName = _configFileProvider.InstanceName + InstanceName = _configFileProvider.InstanceName, + ApplicationUrl = _configService.ApplicationUrl, }; } } diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs index 05d51c7c1..536de2a7b 100755 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookPayload.cs @@ -4,5 +4,6 @@ namespace NzbDrone.Core.Notifications.Webhook { public WebhookEventType EventType { get; set; } public string InstanceName { get; set; } + public string ApplicationUrl { get; set; } } } From a86aa4c5d3315a6cea59bd23d3dac9fca539bec1 Mon Sep 17 00:00:00 2001 From: The Dark <12370876+CheAle14@users.noreply.github.com> Date: Mon, 8 May 2023 02:57:14 +0100 Subject: [PATCH 0008/1209] New: On Health Restored notification (cherry picked from commit 5fdc8514da7c7ad98192f2ecb2415b3a7b5d0d05) --- .../Notifications/Notification.js | 24 +++++++++++++---- .../Notifications/NotificationEventItems.js | 15 ++++++++++- .../NotificationBaseFixture.cs | 7 +++++ .../032_health_restored_notification.cs | 14 ++++++++++ src/NzbDrone.Core/Datastore/TableMapping.cs | 1 + .../HealthCheck/HealthCheckRestoredEvent.cs | 16 ++++++++++++ .../HealthCheck/HealthCheckService.cs | 7 +++++ src/NzbDrone.Core/Localization/Core/en.json | 2 ++ .../Notifications/Apprise/Apprise.cs | 5 ++++ .../Notifications/Boxcar/Boxcar.cs | 5 ++++ .../CustomScript/CustomScript.cs | 15 +++++++++++ .../Notifications/Discord/Discord.cs | 23 ++++++++++++++++ .../Notifications/Email/Email.cs | 5 ++++ .../Notifications/Gotify/Gotify.cs | 5 ++++ .../Notifications/INotification.cs | 2 ++ src/NzbDrone.Core/Notifications/Join/Join.cs | 5 ++++ .../Notifications/Mailgun/Mailgun.cs | 5 ++++ .../Notifications/Notifiarr/Notifiarr.cs | 5 ++++ .../Notifications/NotificationBase.cs | 7 +++++ .../Notifications/NotificationDefinition.cs | 4 ++- .../Notifications/NotificationFactory.cs | 7 +++++ .../Notifications/NotificationService.cs | 26 +++++++++++++++++-- src/NzbDrone.Core/Notifications/Ntfy/Ntfy.cs | 5 ++++ .../Notifications/Prowl/Prowl.cs | 5 ++++ .../Notifications/PushBullet/PushBullet.cs | 5 ++++ .../Notifications/Pushover/Pushover.cs | 5 ++++ .../Notifications/SendGrid/SendGrid.cs | 5 ++++ .../Notifications/Simplepush/Simplepush.cs | 5 ++++ .../Notifications/Slack/Slack.cs | 17 ++++++++++++ .../Notifications/Telegram/Telegram.cs | 5 ++++ .../Notifications/Twitter/Twitter.cs | 5 ++++ .../Notifications/Webhook/Webhook.cs | 5 ++++ .../Notifications/Webhook/WebhookBase.cs | 13 ++++++++++ .../Notifications/Webhook/WebhookEventType.cs | 3 ++- .../Notifications/NotificationResource.cs | 6 +++++ 35 files changed, 279 insertions(+), 10 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/032_health_restored_notification.cs create mode 100644 src/NzbDrone.Core/HealthCheck/HealthCheckRestoredEvent.cs diff --git a/frontend/src/Settings/Notifications/Notifications/Notification.js b/frontend/src/Settings/Notifications/Notifications/Notification.js index 1331a7c8b..66021fd0d 100644 --- a/frontend/src/Settings/Notifications/Notifications/Notification.js +++ b/frontend/src/Settings/Notifications/Notifications/Notification.js @@ -57,9 +57,11 @@ class Notification extends Component { name, onGrab, onHealthIssue, + onHealthRestored, onApplicationUpdate, supportsOnGrab, supportsOnHealthIssue, + supportsOnHealthRestored, supportsOnApplicationUpdate } = this.props; @@ -74,17 +76,27 @@ class Notification extends Component { { - supportsOnGrab && onGrab && + supportsOnGrab && onGrab ? + : + null } { - supportsOnHealthIssue && onHealthIssue && + supportsOnHealthIssue && onHealthIssue ? + : + null + } + + { + supportsOnHealthRestored && onHealthRestored ? + : + null } { @@ -96,7 +108,7 @@ class Notification extends Component { } { - !onGrab && !onHealthIssue && !onApplicationUpdate ? + !onGrab && !onHealthIssue && !onHealthRestored && !onApplicationUpdate ?