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.
54 lines
2.2 KiB
54 lines
2.2 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Download;
|
|
using NzbDrone.Core.Localization;
|
|
using NzbDrone.Core.ThingiProvider.Events;
|
|
|
|
namespace NzbDrone.Core.HealthCheck.Checks
|
|
{
|
|
[CheckOn(typeof(ProviderUpdatedEvent<IDownloadClient>))]
|
|
[CheckOn(typeof(ProviderDeletedEvent<IDownloadClient>))]
|
|
[CheckOn(typeof(ProviderStatusChangedEvent<IDownloadClient>))]
|
|
public class DownloadClientStatusCheck : HealthCheckBase
|
|
{
|
|
private readonly IDownloadClientFactory _providerFactory;
|
|
private readonly IDownloadClientStatusService _providerStatusService;
|
|
|
|
public DownloadClientStatusCheck(IDownloadClientFactory providerFactory, IDownloadClientStatusService providerStatusService, ILocalizationService localizationService)
|
|
: base(localizationService)
|
|
{
|
|
_providerFactory = providerFactory;
|
|
_providerStatusService = providerStatusService;
|
|
}
|
|
|
|
public override HealthCheck Check()
|
|
{
|
|
var enabledProviders = _providerFactory.GetAvailableProviders();
|
|
var backOffProviders = enabledProviders.Join(_providerStatusService.GetBlockedProviders(),
|
|
i => i.Definition.Id,
|
|
s => s.ProviderId,
|
|
(i, s) => new { Provider = i, Status = s })
|
|
.ToList();
|
|
|
|
if (backOffProviders.Empty())
|
|
{
|
|
return new HealthCheck(GetType());
|
|
}
|
|
|
|
if (backOffProviders.Count == enabledProviders.Count)
|
|
{
|
|
return new HealthCheck(GetType(), HealthCheckResult.Error, _localizationService.GetLocalizedString("DownloadClientStatusCheckAllClientMessage"), "#download-clients-are-unavailable-due-to-failures");
|
|
}
|
|
|
|
return new HealthCheck(GetType(),
|
|
HealthCheckResult.Warning,
|
|
_localizationService.GetLocalizedString("DownloadClientStatusCheckSingleClientMessage", new Dictionary<string, object>
|
|
{
|
|
{ "downloadClientNames", string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name)) }
|
|
}),
|
|
"#download-clients-are-unavailable-due-to-failures");
|
|
}
|
|
}
|
|
}
|