mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-20 18:02:44 +01:00
New: Support server notifications
(cherry picked from commit f5f0dd6fae5bc9f308506d56be42ac9a4be908e7) Closes Radarr #5393 [common]
This commit is contained in:
parent
45d8227654
commit
cae5badee0
@ -19,6 +19,10 @@ public void SetUp()
|
|||||||
|
|
||||||
Mocker.SetConstant<IEnumerable<IProvideHealthCheck>>(new[] { _healthCheck });
|
Mocker.SetConstant<IEnumerable<IProvideHealthCheck>>(new[] { _healthCheck });
|
||||||
Mocker.SetConstant<ICacheManager>(Mocker.Resolve<CacheManager>());
|
Mocker.SetConstant<ICacheManager>(Mocker.Resolve<CacheManager>());
|
||||||
|
|
||||||
|
Mocker.GetMock<IServerSideNotificationService>()
|
||||||
|
.Setup(v => v.GetServerChecks())
|
||||||
|
.Returns(new List<Core.HealthCheck.HealthCheck>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -25,6 +25,7 @@ public class HealthCheckService : IHealthCheckService,
|
|||||||
private readonly IProvideHealthCheck[] _startupHealthChecks;
|
private readonly IProvideHealthCheck[] _startupHealthChecks;
|
||||||
private readonly IProvideHealthCheck[] _scheduledHealthChecks;
|
private readonly IProvideHealthCheck[] _scheduledHealthChecks;
|
||||||
private readonly Dictionary<Type, IEventDrivenHealthCheck[]> _eventDrivenHealthChecks;
|
private readonly Dictionary<Type, IEventDrivenHealthCheck[]> _eventDrivenHealthChecks;
|
||||||
|
private readonly IServerSideNotificationService _serverSideNotificationService;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly ICacheManager _cacheManager;
|
private readonly ICacheManager _cacheManager;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
@ -32,11 +33,13 @@ public class HealthCheckService : IHealthCheckService,
|
|||||||
private readonly ICached<HealthCheck> _healthCheckResults;
|
private readonly ICached<HealthCheck> _healthCheckResults;
|
||||||
|
|
||||||
public HealthCheckService(IEnumerable<IProvideHealthCheck> healthChecks,
|
public HealthCheckService(IEnumerable<IProvideHealthCheck> healthChecks,
|
||||||
|
IServerSideNotificationService serverSideNotificationService,
|
||||||
IEventAggregator eventAggregator,
|
IEventAggregator eventAggregator,
|
||||||
ICacheManager cacheManager,
|
ICacheManager cacheManager,
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_healthChecks = healthChecks.ToArray();
|
_healthChecks = healthChecks.ToArray();
|
||||||
|
_serverSideNotificationService = serverSideNotificationService;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_cacheManager = cacheManager;
|
_cacheManager = cacheManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@ -72,6 +75,8 @@ private void PerformHealthCheck(IProvideHealthCheck[] healthChecks)
|
|||||||
var results = healthChecks.Select(c => c.Check())
|
var results = healthChecks.Select(c => c.Check())
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
results.AddRange(_serverSideNotificationService.GetServerChecks());
|
||||||
|
|
||||||
foreach (var result in results)
|
foreach (var result in results)
|
||||||
{
|
{
|
||||||
if (result.Type == HealthCheckResult.Ok)
|
if (result.Type == HealthCheckResult.Ok)
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Cloud;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.HealthCheck
|
||||||
|
{
|
||||||
|
public interface IServerSideNotificationService
|
||||||
|
{
|
||||||
|
public List<HealthCheck> GetServerChecks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ServerSideNotificationService : IServerSideNotificationService
|
||||||
|
{
|
||||||
|
private readonly IHttpClient _client;
|
||||||
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
private readonly IHttpRequestBuilderFactory _cloudRequestBuilder;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public ServerSideNotificationService(IHttpClient client, IConfigFileProvider configFileProvider, IRadarrCloudRequestBuilder cloudRequestBuilder, Logger logger)
|
||||||
|
{
|
||||||
|
_client = client;
|
||||||
|
_configFileProvider = configFileProvider;
|
||||||
|
_cloudRequestBuilder = cloudRequestBuilder.Services;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HealthCheck> GetServerChecks()
|
||||||
|
{
|
||||||
|
var request = _cloudRequestBuilder.Create()
|
||||||
|
.Resource("/notification")
|
||||||
|
.AddQueryParam("version", BuildInfo.Version)
|
||||||
|
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
||||||
|
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
||||||
|
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
|
||||||
|
.AddQueryParam("branch", _configFileProvider.Branch)
|
||||||
|
.Build();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.Trace("Getting server side health notifications");
|
||||||
|
var response = _client.Execute(request);
|
||||||
|
var result = Json.Deserialize<List<ServerNotificationResponse>>(response.Content);
|
||||||
|
return result.Select(x => new HealthCheck(GetType(), x.Type, x.Message, x.WikiUrl)).ToList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex, "Failed to retrieve server notifications");
|
||||||
|
return new List<HealthCheck>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ServerNotificationResponse
|
||||||
|
{
|
||||||
|
public HealthCheckResult Type { get; set; }
|
||||||
|
public string Message { get; set; }
|
||||||
|
public string WikiUrl { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user