New: Handle health checks with matching indexer tags

pull/1979/head
Bogdan 4 months ago
parent ac97952fd7
commit 582d7a202e

@ -40,7 +40,10 @@ namespace NzbDrone.Core.HealthCheck.Checks
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
HealthCheckResult.Warning, HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("IndexerDownloadClientHealthCheckMessage"), string.Join(", ", invalidIndexers.Select(v => v.Name).ToArray())), 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()); return new HealthCheck(GetType());

@ -42,19 +42,27 @@ namespace NzbDrone.Core.HealthCheck.Checks
return new HealthCheck(GetType()); return new HealthCheck(GetType());
} }
var indexerIds = backOffProviders.Select(p => p.Provider.Definition.Id).ToList();
if (backOffProviders.Count == enabledProviders.Count) if (backOffProviders.Count == enabledProviders.Count)
{ {
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
HealthCheckResult.Error, HealthCheckResult.Error,
_localizationService.GetLocalizedString("IndexerLongTermStatusCheckAllClientMessage"), _localizationService.GetLocalizedString("IndexerLongTermStatusCheckAllClientMessage"),
"#indexers-are-unavailable-due-to-failures"); "#indexers-are-unavailable-due-to-failures")
{
IndexerIds = indexerIds
};
} }
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
HealthCheckResult.Warning, HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("IndexerLongTermStatusCheckSingleClientMessage"), string.Format(_localizationService.GetLocalizedString("IndexerLongTermStatusCheckSingleClientMessage"),
string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))), string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))),
"#indexers-are-unavailable-due-to-failures"); "#indexers-are-unavailable-due-to-failures")
{
IndexerIds = indexerIds
};
} }
} }
} }

@ -40,19 +40,27 @@ namespace NzbDrone.Core.HealthCheck.Checks
return new HealthCheck(GetType()); return new HealthCheck(GetType());
} }
var indexerIds = backOffProviders.Select(p => p.Provider.Definition.Id).ToList();
if (backOffProviders.Count == enabledProviders.Count) if (backOffProviders.Count == enabledProviders.Count)
{ {
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
HealthCheckResult.Error, HealthCheckResult.Error,
_localizationService.GetLocalizedString("IndexerStatusCheckAllClientMessage"), _localizationService.GetLocalizedString("IndexerStatusCheckAllClientMessage"),
"#indexers-are-unavailable-due-to-failures"); "#indexers-are-unavailable-due-to-failures")
{
IndexerIds = indexerIds
};
} }
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
HealthCheckResult.Warning, HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("IndexerStatusCheckSingleClientMessage"), string.Format(_localizationService.GetLocalizedString("IndexerStatusCheckSingleClientMessage"),
string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))), string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))),
"#indexers-are-unavailable-due-to-failures"); "#indexers-are-unavailable-due-to-failures")
{
IndexerIds = indexerIds
};
} }
} }
} }

@ -56,7 +56,10 @@ namespace NzbDrone.Core.HealthCheck.Checks
HealthCheckResult.Warning, HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiringClientMessage"), string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiringClientMessage"),
string.Join(", ", expiringProviders.Select(v => v.Definition.Name))), 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()); return new HealthCheck(GetType());

@ -56,7 +56,10 @@ namespace NzbDrone.Core.HealthCheck.Checks
HealthCheckResult.Error, HealthCheckResult.Error,
string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiredClientMessage"), string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiredClientMessage"),
string.Join(", ", expiredProviders.Select(v => v.Definition.Name))), 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()); return new HealthCheck(GetType());

@ -43,7 +43,10 @@ namespace NzbDrone.Core.HealthCheck.Checks
return new HealthCheck(GetType(), return new HealthCheck(GetType(),
healthType, healthType,
healthMessage, healthMessage,
"#indexers-are-obsolete"); "#indexers-are-obsolete")
{
IndexerIds = oldIndexers.Select(i => i.Definition.Id).ToList()
};
} }
public override bool CheckOnSchedule => false; public override bool CheckOnSchedule => false;

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NzbDrone.Common.Http; using NzbDrone.Common.Http;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
@ -7,13 +8,15 @@ namespace NzbDrone.Core.HealthCheck
{ {
public class HealthCheck : ModelBase 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 Type Source { get; set; }
public HealthCheckResult Type { get; set; } public HealthCheckResult Type { get; set; }
public string Message { get; set; } public string Message { get; set; }
public HttpUri WikiUrl { get; set; } public HttpUri WikiUrl { get; set; }
public List<int> IndexerIds { get; set; } = new ();
public HealthCheck() public HealthCheck()
{ {
} }

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@ -21,12 +22,14 @@ namespace NzbDrone.Core.Notifications
{ {
private readonly INotificationFactory _notificationFactory; private readonly INotificationFactory _notificationFactory;
private readonly INotificationStatusService _notificationStatusService; private readonly INotificationStatusService _notificationStatusService;
private readonly IIndexerFactory _indexerFactory;
private readonly Logger _logger; private readonly Logger _logger;
public NotificationService(INotificationFactory notificationFactory, INotificationStatusService notificationStatusService, Logger logger) public NotificationService(INotificationFactory notificationFactory, INotificationStatusService notificationStatusService, IIndexerFactory indexerFactory, Logger logger)
{ {
_notificationFactory = notificationFactory; _notificationFactory = notificationFactory;
_notificationStatusService = notificationStatusService; _notificationStatusService = notificationStatusService;
_indexerFactory = indexerFactory;
_logger = logger; _logger = logger;
} }
@ -85,7 +88,8 @@ namespace NzbDrone.Core.Notifications
{ {
try 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); notification.OnHealthIssue(message.HealthCheck);
_notificationStatusService.RecordSuccess(notification.Definition.Id); _notificationStatusService.RecordSuccess(notification.Definition.Id);
@ -110,7 +114,8 @@ namespace NzbDrone.Core.Notifications
{ {
try 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); notification.OnHealthRestored(message.PreviousCheck);
_notificationStatusService.RecordSuccess(notification.Definition.Id); _notificationStatusService.RecordSuccess(notification.Definition.Id);
@ -201,6 +206,18 @@ namespace NzbDrone.Core.Notifications
} }
} }
private bool ShouldHandleIndexers(ProviderDefinition definition, IList<int> 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) private bool ShouldHandleIndexer(ProviderDefinition definition, ProviderDefinition indexer)
{ {
if (definition.Tags.Empty()) if (definition.Tags.Empty())

Loading…
Cancel
Save