From 3c5eefc3498523def7992eb332108f2574e84493 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 4 Aug 2023 03:38:53 +0300 Subject: [PATCH] New: Health check for indexers with invalid download client (cherry picked from commit 377fce6fe15c0875c4bd33f1371a31af79c9310c) --- .../Checks/IndexerDownloadClientCheck.cs | 49 +++++++++++++++++++ src/NzbDrone.Core/Localization/Core/en.json | 1 + 2 files changed, 50 insertions(+) create mode 100644 src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs diff --git a/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs new file mode 100644 index 000000000..0d1682efc --- /dev/null +++ b/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs @@ -0,0 +1,49 @@ +using System.Linq; +using NzbDrone.Core.Download; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Localization; +using NzbDrone.Core.ThingiProvider.Events; + +namespace NzbDrone.Core.HealthCheck.Checks +{ + [CheckOn(typeof(ProviderUpdatedEvent))] + [CheckOn(typeof(ProviderDeletedEvent))] + [CheckOn(typeof(ProviderBulkUpdatedEvent))] + [CheckOn(typeof(ProviderBulkDeletedEvent))] + [CheckOn(typeof(ProviderUpdatedEvent))] + [CheckOn(typeof(ProviderDeletedEvent))] + [CheckOn(typeof(ProviderBulkUpdatedEvent))] + [CheckOn(typeof(ProviderBulkDeletedEvent))] + public class IndexerDownloadClientCheck : HealthCheckBase + { + private readonly IIndexerFactory _indexerFactory; + private readonly IDownloadClientFactory _downloadClientFactory; + + public IndexerDownloadClientCheck(IIndexerFactory indexerFactory, + IDownloadClientFactory downloadClientFactory, + ILocalizationService localizationService) + : base(localizationService) + { + _indexerFactory = indexerFactory; + _downloadClientFactory = downloadClientFactory; + } + + public override HealthCheck Check() + { + var downloadClientsIds = _downloadClientFactory.All().Where(v => v.Enable).Select(v => v.Id).ToList(); + var invalidIndexers = _indexerFactory.All() + .Where(v => v.Enable && v.DownloadClientId > 0 && !downloadClientsIds.Contains(v.DownloadClientId)) + .ToList(); + + if (invalidIndexers.Any()) + { + return new HealthCheck(GetType(), + HealthCheckResult.Warning, + string.Format(_localizationService.GetLocalizedString("IndexerDownloadClientHealthCheckMessage"), string.Join(", ", invalidIndexers.Select(v => v.Name).ToArray())), + "#invalid-indexer-download-client-setting"); + } + + return new HealthCheck(GetType()); + } + } +} diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index a8d6e58f6..8c267fcae 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -229,6 +229,7 @@ "IndexerCategories": "Indexer Categories", "IndexerDetails": "Indexer Details", "IndexerDisabled": "Indexer Disabled", + "IndexerDownloadClientHealthCheckMessage": "Indexers with invalid download clients: {0}.", "IndexerDownloadClientHelpText": "Specify which download client is used for grabs made within Prowlarr from this indexer", "IndexerFailureRate": "Indexer Failure Rate", "IndexerFlags": "Indexer Flags",