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(),
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());

@ -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
};
}
}
}

@ -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
};
}
}
}

@ -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());

@ -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());

@ -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;

@ -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<int> IndexerIds { get; set; } = new ();
public HealthCheck()
{
}

@ -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<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)
{
if (definition.Tags.Empty())

Loading…
Cancel
Save