mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
WIP
This commit is contained in:
parent
99d9ccc7dd
commit
db2e3bd08c
14 changed files with 306 additions and 54 deletions
26
src/Ombi.HealthChecks/Checks/BaseHealthCheck.cs
Normal file
26
src/Ombi.HealthChecks/Checks/BaseHealthCheck.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.HealthChecks.Checks
|
||||||
|
{
|
||||||
|
public abstract class BaseHealthCheck : IHealthCheck
|
||||||
|
{
|
||||||
|
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||||
|
public BaseHealthCheck(IServiceScopeFactory serviceScopeFactory)
|
||||||
|
{
|
||||||
|
_serviceScopeFactory = serviceScopeFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
protected IServiceScope CreateScope()
|
||||||
|
{
|
||||||
|
return _serviceScopeFactory.CreateScope();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
src/Ombi.HealthChecks/Checks/EmbyHealthCheck.cs
Normal file
53
src/Ombi.HealthChecks/Checks/EmbyHealthCheck.cs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Ombi.Api.Emby;
|
||||||
|
using Ombi.Api.Emby.Models;
|
||||||
|
using Ombi.Api.Plex;
|
||||||
|
using Ombi.Api.Plex.Models.Status;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Core.Settings.Models.External;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.HealthChecks.Checks
|
||||||
|
{
|
||||||
|
public class EmbyHealthCheck : BaseHealthCheck
|
||||||
|
{
|
||||||
|
public EmbyHealthCheck(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override async Task<HealthCheckResult> CheckHealthAsync(
|
||||||
|
HealthCheckContext context,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using (var scope = CreateScope())
|
||||||
|
{
|
||||||
|
var settingsProvider = scope.ServiceProvider.GetRequiredService<ISettingsService<EmbySettings>>();
|
||||||
|
var api = scope.ServiceProvider.GetRequiredService<IEmbyApi>();
|
||||||
|
var settings = await settingsProvider.GetSettingsAsync();
|
||||||
|
if (settings == null)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy("Emby is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var taskResult = new List<Task<EmbySystemInfo>>();
|
||||||
|
foreach (var server in settings.Servers)
|
||||||
|
{
|
||||||
|
taskResult.Add(api.GetSystemInformation(server.ApiKey, server.FullUri));
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await Task.WhenAll(taskResult.ToArray());
|
||||||
|
return HealthCheckResult.Healthy();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Unhealthy("Could not communicate with Emby", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
src/Ombi.HealthChecks/Checks/LidarrHealthCheck.cs
Normal file
48
src/Ombi.HealthChecks/Checks/LidarrHealthCheck.cs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Ombi.Api.Lidarr;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Settings.Settings.Models.External;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.HealthChecks.Checks
|
||||||
|
{
|
||||||
|
public class LidarrHealthCheck : BaseHealthCheck
|
||||||
|
{
|
||||||
|
public LidarrHealthCheck(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<HealthCheckResult> CheckHealthAsync(
|
||||||
|
HealthCheckContext context,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using (var scope = CreateScope())
|
||||||
|
{
|
||||||
|
var settingsProvider = scope.ServiceProvider.GetRequiredService<ISettingsService<LidarrSettings>>();
|
||||||
|
var api = scope.ServiceProvider.GetRequiredService<ILidarrApi>();
|
||||||
|
var settings = await settingsProvider.GetSettingsAsync();
|
||||||
|
if (!settings.Enabled)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy("Lidarr is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await api.Status(settings.ApiKey, settings.FullUri);
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy();
|
||||||
|
}
|
||||||
|
return HealthCheckResult.Degraded("Couldn't get the status from Lidarr");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Unhealthy("Could not communicate with Lidarr", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs
Normal file
51
src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Ombi.Api.Plex;
|
||||||
|
using Ombi.Api.Plex.Models.Status;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Core.Settings.Models.External;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.HealthChecks.Checks
|
||||||
|
{
|
||||||
|
public class PlexHealthCheck : BaseHealthCheck
|
||||||
|
{
|
||||||
|
public PlexHealthCheck(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override async Task<HealthCheckResult> CheckHealthAsync(
|
||||||
|
HealthCheckContext context,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using (var scope = CreateScope())
|
||||||
|
{
|
||||||
|
var settingsProvider = scope.ServiceProvider.GetRequiredService<ISettingsService<PlexSettings>>();
|
||||||
|
var api = scope.ServiceProvider.GetRequiredService<IPlexApi>();
|
||||||
|
var settings = await settingsProvider.GetSettingsAsync();
|
||||||
|
if (settings == null)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy("Plex is not confiured.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var taskResult = new List<Task<PlexStatus>>();
|
||||||
|
foreach (var server in settings.Servers)
|
||||||
|
{
|
||||||
|
taskResult.Add(api.GetStatus(server.PlexAuthToken, server.FullUri));
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await Task.WhenAll(taskResult.ToArray());
|
||||||
|
return HealthCheckResult.Healthy();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Unhealthy("Could not communicate with Plex", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
src/Ombi.HealthChecks/Checks/RadarrHealthCheck.cs
Normal file
47
src/Ombi.HealthChecks/Checks/RadarrHealthCheck.cs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Ombi.Api.Radarr;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Settings.Settings.Models.External;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.HealthChecks.Checks
|
||||||
|
{
|
||||||
|
public class RadarrHealthCheck : BaseHealthCheck, IHealthCheck
|
||||||
|
{
|
||||||
|
public RadarrHealthCheck(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override async Task<HealthCheckResult> CheckHealthAsync(
|
||||||
|
HealthCheckContext context,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using (var scope = CreateScope())
|
||||||
|
{
|
||||||
|
var settingsProvider = scope.ServiceProvider.GetRequiredService<ISettingsService<RadarrSettings>>();
|
||||||
|
var api = scope.ServiceProvider.GetRequiredService<IRadarrApi>();
|
||||||
|
var settings = await settingsProvider.GetSettingsAsync();
|
||||||
|
if (!settings.Enabled)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy("Radarr is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await api.SystemStatus(settings.ApiKey, settings.FullUri);
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy();
|
||||||
|
}
|
||||||
|
return HealthCheckResult.Degraded("Couldn't get the status from Radarr");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Unhealthy("Could not communicate with Radarr", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
src/Ombi.HealthChecks/Checks/SonarrHealthCheck.cs
Normal file
48
src/Ombi.HealthChecks/Checks/SonarrHealthCheck.cs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
using Ombi.Api.Sonarr;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Settings.Settings.Models.External;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.HealthChecks.Checks
|
||||||
|
{
|
||||||
|
public class SonarrHealthCheck : BaseHealthCheck
|
||||||
|
{
|
||||||
|
public SonarrHealthCheck(IServiceScopeFactory serviceScopeFactory) : base(serviceScopeFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<HealthCheckResult> CheckHealthAsync(
|
||||||
|
HealthCheckContext context,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using (var scope = CreateScope())
|
||||||
|
{
|
||||||
|
var settingsProvider = scope.ServiceProvider.GetRequiredService<ISettingsService<SonarrSettings>>();
|
||||||
|
var api = scope.ServiceProvider.GetRequiredService<ISonarrApi>();
|
||||||
|
var settings = await settingsProvider.GetSettingsAsync();
|
||||||
|
if (!settings.Enabled)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy("Sonarr is not configured.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await api.SystemStatus(settings.ApiKey, settings.FullUri);
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Healthy();
|
||||||
|
}
|
||||||
|
return HealthCheckResult.Degraded("Couldn't get the status from Sonarr");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return HealthCheckResult.Unhealthy("Could not communicate with Sonarr", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,17 @@
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
using Ombi.HealthChecks.Checks;
|
||||||
|
|
||||||
namespace Ombi.HealthChecks
|
namespace Ombi.HealthChecks
|
||||||
{
|
{
|
||||||
public static class HealthCheckExtensions
|
public static class HealthCheckExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
public static IHealthChecksBuilder AddOmbiHealthChecks(this IHealthChecksBuilder builder)
|
public static IHealthChecksBuilder AddOmbiHealthChecks(this IHealthChecksBuilder builder)
|
||||||
{
|
{
|
||||||
builder.AddCheck<PlexHealthCheck>("Plex", tags: new string[] { "MediaServer" });
|
builder.AddCheck<PlexHealthCheck>("Plex", tags: new string[] { "MediaServer" });
|
||||||
|
builder.AddCheck<EmbyHealthCheck>("Emby", tags: new string[] { "MediaServer" });
|
||||||
|
builder.AddCheck<LidarrHealthCheck>("Lidarr", tags: new string[] { "DVR" });
|
||||||
|
builder.AddCheck<SonarrHealthCheck>("Sonarr", tags: new string[] { "DVR" });
|
||||||
|
builder.AddCheck<RadarrHealthCheck>("Radarr", tags: new string[] { "DVR" });
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,11 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Ombi.Api.Emby\Ombi.Api.Emby.csproj" />
|
||||||
|
<ProjectReference Include="..\Ombi.Api.Lidarr\Ombi.Api.Lidarr.csproj" />
|
||||||
<ProjectReference Include="..\Ombi.Api.Plex\Ombi.Api.Plex.csproj" />
|
<ProjectReference Include="..\Ombi.Api.Plex\Ombi.Api.Plex.csproj" />
|
||||||
|
<ProjectReference Include="..\Ombi.Api.Radarr\Ombi.Api.Radarr.csproj" />
|
||||||
|
<ProjectReference Include="..\Ombi.Api.Sonarr\Ombi.Api.Sonarr.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
|
||||||
using Ombi.Api.Plex;
|
|
||||||
using Ombi.Api.Plex.Models.Status;
|
|
||||||
using Ombi.Core.Settings;
|
|
||||||
using Ombi.Core.Settings.Models.External;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Ombi.HealthChecks
|
|
||||||
{
|
|
||||||
public class PlexHealthCheck : IHealthCheck
|
|
||||||
{
|
|
||||||
private readonly IPlexApi _plexApi;
|
|
||||||
private readonly ISettingsService<PlexSettings> _settings;
|
|
||||||
public PlexHealthCheck(IPlexApi plexApi, ISettingsService<PlexSettings> settings)
|
|
||||||
{
|
|
||||||
_plexApi = plexApi;
|
|
||||||
_settings = settings;
|
|
||||||
}
|
|
||||||
public async Task<HealthCheckResult> CheckHealthAsync(
|
|
||||||
HealthCheckContext context,
|
|
||||||
CancellationToken cancellationToken = default(CancellationToken))
|
|
||||||
{
|
|
||||||
var settings = await _settings.GetSettingsAsync();
|
|
||||||
if (settings == null)
|
|
||||||
{
|
|
||||||
return HealthCheckResult.Healthy("Plex is not confiured.");
|
|
||||||
}
|
|
||||||
|
|
||||||
var taskResult = new List<Task<PlexStatus>>();
|
|
||||||
foreach (var server in settings.Servers)
|
|
||||||
{
|
|
||||||
taskResult.Add(_plexApi.GetStatus(server.PlexAuthToken, server.FullUri));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = await Task.WhenAll(taskResult.ToArray());
|
|
||||||
return HealthCheckResult.Healthy();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return HealthCheckResult.Unhealthy("Could not communicate with Plex", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
2
src/Ombi/.gitignore
vendored
2
src/Ombi/.gitignore
vendored
|
@ -7,4 +7,4 @@ wwwroot/dist
|
||||||
/connect.lock
|
/connect.lock
|
||||||
/coverage/*
|
/coverage/*
|
||||||
/Logs/**
|
/Logs/**
|
||||||
**.db
|
**.db
|
13
src/Ombi/HealthCheck.css
Normal file
13
src/Ombi/HealthCheck.css
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
:root {
|
||||||
|
--primaryColor: #424242;
|
||||||
|
--secondaryColor: #f9dc43;
|
||||||
|
--bgMenuActive: #f9dc43;
|
||||||
|
--bgButton: #f9dc43;
|
||||||
|
--logoImageUrl: url('https://ombi.io/img/logo-orange-small.png');
|
||||||
|
--bgAside: var(--primaryColor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#outer-container > aside > nav > a:nth-child(2) {
|
||||||
|
display: none;
|
||||||
|
}
|
|
@ -98,6 +98,12 @@
|
||||||
<ProjectReference Include="..\Ombi.Updater\Ombi.Updater.csproj" />
|
<ProjectReference Include="..\Ombi.Updater\Ombi.Updater.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="HealthCheck.css">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
|
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
|
||||||
|
|
|
@ -218,7 +218,10 @@ namespace Ombi
|
||||||
Predicate = _ => true,
|
Predicate = _ => true,
|
||||||
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
||||||
});
|
});
|
||||||
endpoints.MapHealthChecksUI();
|
endpoints.MapHealthChecksUI(opts =>
|
||||||
|
{
|
||||||
|
opts.AddCustomStylesheet("HealthCheck.css");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseSpa(spa =>
|
app.UseSpa(spa =>
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue