You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prowlarr/src/NzbDrone.Core/HealthCheck/Checks/IndexerDownloadClientCheck.cs

53 lines
2.2 KiB

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<IIndexer>))]
[CheckOn(typeof(ProviderDeletedEvent<IIndexer>))]
[CheckOn(typeof(ProviderBulkUpdatedEvent<IIndexer>))]
[CheckOn(typeof(ProviderBulkDeletedEvent<IIndexer>))]
[CheckOn(typeof(ProviderUpdatedEvent<IDownloadClient>))]
[CheckOn(typeof(ProviderDeletedEvent<IDownloadClient>))]
[CheckOn(typeof(ProviderBulkUpdatedEvent<IDownloadClient>))]
[CheckOn(typeof(ProviderBulkDeletedEvent<IDownloadClient>))]
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")
{
IndexerIds = invalidIndexers.Select(i => i.Id).ToList()
};
}
return new HealthCheck(GetType());
}
}
}