-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: VIP Healthcheck not triggered for expired indexers
- Loading branch information
Showing
2 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/NzbDrone.Core/HealthCheck/Checks/IndexerVIPExpiredCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |