From 582d7a202e13d7e99a6eda9bd36d5ef71e2e7b60 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 9 Jan 2024 20:22:23 +0200 Subject: [PATCH] New: Handle health checks with matching indexer tags --- .../Checks/IndexerDownloadClientCheck.cs | 5 +++- .../Checks/IndexerLongTermStatusCheck.cs | 12 ++++++++-- .../HealthCheck/Checks/IndexerStatusCheck.cs | 12 ++++++++-- .../HealthCheck/Checks/IndexerVIPCheck.cs | 5 +++- .../Checks/IndexerVIPExpiredCheck.cs | 5 +++- .../Checks/OutdatedDefinitionCheck.cs | 5 +++- src/NzbDrone.Core/HealthCheck/HealthCheck.cs | 5 +++- .../Notifications/NotificationService.cs | 23 ++++++++++++++++--- 8 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs index 0d1682efc..6c8e3a664 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs @@ -40,7 +40,10 @@ namespace NzbDrone.Core.HealthCheck.Checks return new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format(_localizationService.GetLocalizedString("IndexerDownloadClientHealthCheckMessage"), string.Join(", ", invalidIndexers.Select(v => v.Name).ToArray())), - "#invalid-indexer-download-client-setting"); + "#invalid-indexer-download-client-setting") + { + IndexerIds = invalidIndexers.Select(i => i.Id).ToList() + }; } return new HealthCheck(GetType()); diff --git a/src/NzbDrone.Core/HealthCheck/Checks/IndexerLongTermStatusCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/IndexerLongTermStatusCheck.cs index 758259a13..e2ab7685e 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/IndexerLongTermStatusCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/IndexerLongTermStatusCheck.cs @@ -42,19 +42,27 @@ namespace NzbDrone.Core.HealthCheck.Checks return new HealthCheck(GetType()); } + var indexerIds = backOffProviders.Select(p => p.Provider.Definition.Id).ToList(); + if (backOffProviders.Count == enabledProviders.Count) { return new HealthCheck(GetType(), HealthCheckResult.Error, _localizationService.GetLocalizedString("IndexerLongTermStatusCheckAllClientMessage"), - "#indexers-are-unavailable-due-to-failures"); + "#indexers-are-unavailable-due-to-failures") + { + IndexerIds = indexerIds + }; } return new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format(_localizationService.GetLocalizedString("IndexerLongTermStatusCheckSingleClientMessage"), string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))), - "#indexers-are-unavailable-due-to-failures"); + "#indexers-are-unavailable-due-to-failures") + { + IndexerIds = indexerIds + }; } } } diff --git a/src/NzbDrone.Core/HealthCheck/Checks/IndexerStatusCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/IndexerStatusCheck.cs index 968cb5e8f..894af8b3e 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/IndexerStatusCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/IndexerStatusCheck.cs @@ -40,19 +40,27 @@ namespace NzbDrone.Core.HealthCheck.Checks return new HealthCheck(GetType()); } + var indexerIds = backOffProviders.Select(p => p.Provider.Definition.Id).ToList(); + if (backOffProviders.Count == enabledProviders.Count) { return new HealthCheck(GetType(), HealthCheckResult.Error, _localizationService.GetLocalizedString("IndexerStatusCheckAllClientMessage"), - "#indexers-are-unavailable-due-to-failures"); + "#indexers-are-unavailable-due-to-failures") + { + IndexerIds = indexerIds + }; } return new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format(_localizationService.GetLocalizedString("IndexerStatusCheckSingleClientMessage"), string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))), - "#indexers-are-unavailable-due-to-failures"); + "#indexers-are-unavailable-due-to-failures") + { + IndexerIds = indexerIds + }; } } } diff --git a/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPCheck.cs index 4265b5963..ee5a73917 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPCheck.cs @@ -56,7 +56,10 @@ namespace NzbDrone.Core.HealthCheck.Checks HealthCheckResult.Warning, string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiringClientMessage"), string.Join(", ", expiringProviders.Select(v => v.Definition.Name))), - "#indexer-vip-expiring"); + "#indexer-vip-expiring") + { + IndexerIds = expiringProviders.Select(p => p.Definition.Id).ToList() + }; } return new HealthCheck(GetType()); diff --git a/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPExpiredCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPExpiredCheck.cs index 8b0dd06e7..a38201870 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPExpiredCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPExpiredCheck.cs @@ -56,7 +56,10 @@ namespace NzbDrone.Core.HealthCheck.Checks HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiredClientMessage"), string.Join(", ", expiredProviders.Select(v => v.Definition.Name))), - "#indexer-vip-expired"); + "#indexer-vip-expired") + { + IndexerIds = expiredProviders.Select(p => p.Definition.Id).ToList() + }; } return new HealthCheck(GetType()); diff --git a/src/NzbDrone.Core/HealthCheck/Checks/OutdatedDefinitionCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/OutdatedDefinitionCheck.cs index c79d8dc71..00e098ed1 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/OutdatedDefinitionCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/OutdatedDefinitionCheck.cs @@ -43,7 +43,10 @@ namespace NzbDrone.Core.HealthCheck.Checks return new HealthCheck(GetType(), healthType, healthMessage, - "#indexers-are-obsolete"); + "#indexers-are-obsolete") + { + IndexerIds = oldIndexers.Select(i => i.Definition.Id).ToList() + }; } public override bool CheckOnSchedule => false; diff --git a/src/NzbDrone.Core/HealthCheck/HealthCheck.cs b/src/NzbDrone.Core/HealthCheck/HealthCheck.cs index 1eba4c46f..278bebac7 100644 --- a/src/NzbDrone.Core/HealthCheck/HealthCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/HealthCheck.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text.RegularExpressions; using NzbDrone.Common.Http; using NzbDrone.Core.Datastore; @@ -7,13 +8,15 @@ namespace NzbDrone.Core.HealthCheck { public class HealthCheck : ModelBase { - private static readonly Regex CleanFragmentRegex = new Regex("[^a-z ]", RegexOptions.Compiled); + private static readonly Regex CleanFragmentRegex = new ("[^a-z ]", RegexOptions.Compiled); public Type Source { get; set; } public HealthCheckResult Type { get; set; } public string Message { get; set; } public HttpUri WikiUrl { get; set; } + public List IndexerIds { get; set; } = new (); + public HealthCheck() { } diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index ab4473023..748eb7e58 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common.Extensions; @@ -21,12 +22,14 @@ namespace NzbDrone.Core.Notifications { private readonly INotificationFactory _notificationFactory; private readonly INotificationStatusService _notificationStatusService; + private readonly IIndexerFactory _indexerFactory; private readonly Logger _logger; - public NotificationService(INotificationFactory notificationFactory, INotificationStatusService notificationStatusService, Logger logger) + public NotificationService(INotificationFactory notificationFactory, INotificationStatusService notificationStatusService, IIndexerFactory indexerFactory, Logger logger) { _notificationFactory = notificationFactory; _notificationStatusService = notificationStatusService; + _indexerFactory = indexerFactory; _logger = logger; } @@ -85,7 +88,8 @@ namespace NzbDrone.Core.Notifications { try { - if (ShouldHandleHealthFailure(message.HealthCheck, ((NotificationDefinition)notification.Definition).IncludeHealthWarnings)) + if (ShouldHandleIndexers(notification.Definition, message.HealthCheck.IndexerIds) && + ShouldHandleHealthFailure(message.HealthCheck, ((NotificationDefinition)notification.Definition).IncludeHealthWarnings)) { notification.OnHealthIssue(message.HealthCheck); _notificationStatusService.RecordSuccess(notification.Definition.Id); @@ -110,7 +114,8 @@ namespace NzbDrone.Core.Notifications { try { - if (ShouldHandleHealthFailure(message.PreviousCheck, ((NotificationDefinition)notification.Definition).IncludeHealthWarnings)) + if (ShouldHandleIndexers(notification.Definition, message.PreviousCheck.IndexerIds) && + ShouldHandleHealthFailure(message.PreviousCheck, ((NotificationDefinition)notification.Definition).IncludeHealthWarnings)) { notification.OnHealthRestored(message.PreviousCheck); _notificationStatusService.RecordSuccess(notification.Definition.Id); @@ -201,6 +206,18 @@ namespace NzbDrone.Core.Notifications } } + private bool ShouldHandleIndexers(ProviderDefinition definition, IList indexerIds) + { + if (!indexerIds.Any()) + { + return true; + } + + var indexers = _indexerFactory.Get(indexerIds).ToList(); + + return indexers.Any(indexer => ShouldHandleIndexer(definition, indexer)); + } + private bool ShouldHandleIndexer(ProviderDefinition definition, ProviderDefinition indexer) { if (definition.Tags.Empty())