Fixed: VIP Healthcheck not triggered for expired indexers

pull/1045/head
Qstick 2 years ago
parent 479e29dde7
commit 86f5768461

@ -23,11 +23,10 @@ namespace NzbDrone.Core.HealthCheck.Checks
public override HealthCheck Check() public override HealthCheck Check()
{ {
var enabled = _indexerFactory.Enabled(false); var indexers = _indexerFactory.AllProviders(false);
var expiringProviders = new List<IIndexer>(); var expiringProviders = new List<IIndexer>();
var expiredProviders = new List<IIndexer>();
foreach (var provider in enabled) foreach (var provider in indexers)
{ {
var settingsType = provider.Definition.Settings.GetType(); var settingsType = provider.Definition.Settings.GetType();
var vipProp = settingsType.GetProperty("VipExpiration"); var vipProp = settingsType.GetProperty("VipExpiration");
@ -44,11 +43,6 @@ namespace NzbDrone.Core.HealthCheck.Checks
continue; continue;
} }
if (DateTime.Parse(expiration).Before(DateTime.Now))
{
expiredProviders.Add(provider);
}
if (DateTime.Parse(expiration).Between(DateTime.Now, DateTime.Now.AddDays(7))) if (DateTime.Parse(expiration).Between(DateTime.Now, DateTime.Now.AddDays(7)))
{ {
expiringProviders.Add(provider); expiringProviders.Add(provider);
@ -64,15 +58,6 @@ namespace NzbDrone.Core.HealthCheck.Checks
"#indexer-vip-expiring"); "#indexer-vip-expiring");
} }
if (!expiredProviders.Empty())
{
return new HealthCheck(GetType(),
HealthCheckResult.Warning,
string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiredClientMessage"),
string.Join(", ", expiredProviders.Select(v => v.Definition.Name))),
"#indexer-vip-expired");
}
return new HealthCheck(GetType()); return new HealthCheck(GetType());
} }
} }

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Localization;
using NzbDrone.Core.ThingiProvider.Events;
namespace NzbDrone.Core.HealthCheck.Checks
{
[CheckOn(typeof(ProviderAddedEvent<IIndexer>))]
[CheckOn(typeof(ProviderUpdatedEvent<IIndexer>))]
[CheckOn(typeof(ProviderDeletedEvent<IIndexer>))]
public class IndexerVIPExpiredCheck : HealthCheckBase
{
private readonly IIndexerFactory _indexerFactory;
public IndexerVIPExpiredCheck(IIndexerFactory indexerFactory, ILocalizationService localizationService)
: base(localizationService)
{
_indexerFactory = indexerFactory;
}
public override HealthCheck Check()
{
var indexers = _indexerFactory.AllProviders(false);
var expiredProviders = new List<IIndexer>();
foreach (var provider in indexers)
{
var settingsType = provider.Definition.Settings.GetType();
var vipProp = settingsType.GetProperty("VipExpiration");
if (vipProp == null)
{
continue;
}
var expiration = (string)vipProp.GetValue(provider.Definition.Settings);
if (expiration.IsNullOrWhiteSpace())
{
continue;
}
if (DateTime.Parse(expiration).Before(DateTime.Now))
{
expiredProviders.Add(provider);
}
}
if (!expiredProviders.Empty())
{
return new HealthCheck(GetType(),
HealthCheckResult.Error,
string.Format(_localizationService.GetLocalizedString("IndexerVipCheckExpiredClientMessage"),
string.Join(", ", expiredProviders.Select(v => v.Definition.Name))),
"#indexer-vip-expired");
}
return new HealthCheck(GetType());
}
}
}
Loading…
Cancel
Save