From db2e3bd08c07a39291b9a7a5c21383b75026d9fc Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 17 Feb 2020 16:34:59 +0000 Subject: [PATCH] WIP --- .../Checks/BaseHealthCheck.cs | 26 +++++++++ .../Checks/EmbyHealthCheck.cs | 53 ++++++++++++++++++ .../Checks/LidarrHealthCheck.cs | 48 ++++++++++++++++ .../Checks/PlexHealthCheck.cs | 51 +++++++++++++++++ .../Checks/RadarrHealthCheck.cs | 47 ++++++++++++++++ .../Checks/SonarrHealthCheck.cs | 48 ++++++++++++++++ .../HealthCheckExtensions.cs | 7 ++- .../Ombi.HealthChecks.csproj | 4 ++ src/Ombi.HealthChecks/PlexHealthCheck.cs | 50 ----------------- src/Ombi/.gitignore | 2 +- src/Ombi/HealthCheck.css | 13 +++++ src/Ombi/Ombi.csproj | 6 ++ src/Ombi/Startup.cs | 5 +- src/Ombi/healthchecksdb | Bin 45056 -> 45056 bytes 14 files changed, 306 insertions(+), 54 deletions(-) create mode 100644 src/Ombi.HealthChecks/Checks/BaseHealthCheck.cs create mode 100644 src/Ombi.HealthChecks/Checks/EmbyHealthCheck.cs create mode 100644 src/Ombi.HealthChecks/Checks/LidarrHealthCheck.cs create mode 100644 src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs create mode 100644 src/Ombi.HealthChecks/Checks/RadarrHealthCheck.cs create mode 100644 src/Ombi.HealthChecks/Checks/SonarrHealthCheck.cs delete mode 100644 src/Ombi.HealthChecks/PlexHealthCheck.cs create mode 100644 src/Ombi/HealthCheck.css diff --git a/src/Ombi.HealthChecks/Checks/BaseHealthCheck.cs b/src/Ombi.HealthChecks/Checks/BaseHealthCheck.cs new file mode 100644 index 000000000..d0c14196c --- /dev/null +++ b/src/Ombi.HealthChecks/Checks/BaseHealthCheck.cs @@ -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 CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default); + + protected IServiceScope CreateScope() + { + return _serviceScopeFactory.CreateScope(); + } + } +} diff --git a/src/Ombi.HealthChecks/Checks/EmbyHealthCheck.cs b/src/Ombi.HealthChecks/Checks/EmbyHealthCheck.cs new file mode 100644 index 000000000..d601cdeef --- /dev/null +++ b/src/Ombi.HealthChecks/Checks/EmbyHealthCheck.cs @@ -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 CheckHealthAsync( + HealthCheckContext context, + CancellationToken cancellationToken = default) + { + using (var scope = CreateScope()) + { + var settingsProvider = scope.ServiceProvider.GetRequiredService>(); + var api = scope.ServiceProvider.GetRequiredService(); + var settings = await settingsProvider.GetSettingsAsync(); + if (settings == null) + { + return HealthCheckResult.Healthy("Emby is not configured."); + } + + var taskResult = new List>(); + 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); + } + } + } + } +} diff --git a/src/Ombi.HealthChecks/Checks/LidarrHealthCheck.cs b/src/Ombi.HealthChecks/Checks/LidarrHealthCheck.cs new file mode 100644 index 000000000..4efc0a904 --- /dev/null +++ b/src/Ombi.HealthChecks/Checks/LidarrHealthCheck.cs @@ -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 CheckHealthAsync( + HealthCheckContext context, + CancellationToken cancellationToken = default) + { + using (var scope = CreateScope()) + { + var settingsProvider = scope.ServiceProvider.GetRequiredService>(); + var api = scope.ServiceProvider.GetRequiredService(); + 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); + } + } + } + } +} diff --git a/src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs b/src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs new file mode 100644 index 000000000..182c1b2f8 --- /dev/null +++ b/src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs @@ -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 CheckHealthAsync( + HealthCheckContext context, + CancellationToken cancellationToken = default) + { + using (var scope = CreateScope()) + { + var settingsProvider = scope.ServiceProvider.GetRequiredService>(); + var api = scope.ServiceProvider.GetRequiredService(); + var settings = await settingsProvider.GetSettingsAsync(); + if (settings == null) + { + return HealthCheckResult.Healthy("Plex is not confiured."); + } + + var taskResult = new List>(); + 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); + } + } + } + } +} diff --git a/src/Ombi.HealthChecks/Checks/RadarrHealthCheck.cs b/src/Ombi.HealthChecks/Checks/RadarrHealthCheck.cs new file mode 100644 index 000000000..e365c73bb --- /dev/null +++ b/src/Ombi.HealthChecks/Checks/RadarrHealthCheck.cs @@ -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 CheckHealthAsync( + HealthCheckContext context, + CancellationToken cancellationToken = default) + { + using (var scope = CreateScope()) + { + var settingsProvider = scope.ServiceProvider.GetRequiredService>(); + var api = scope.ServiceProvider.GetRequiredService(); + 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); + } + } + } + } +} diff --git a/src/Ombi.HealthChecks/Checks/SonarrHealthCheck.cs b/src/Ombi.HealthChecks/Checks/SonarrHealthCheck.cs new file mode 100644 index 000000000..35f2bb46a --- /dev/null +++ b/src/Ombi.HealthChecks/Checks/SonarrHealthCheck.cs @@ -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 CheckHealthAsync( + HealthCheckContext context, + CancellationToken cancellationToken = default) + { + using (var scope = CreateScope()) + { + var settingsProvider = scope.ServiceProvider.GetRequiredService>(); + var api = scope.ServiceProvider.GetRequiredService(); + 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); + } + } + } + } +} diff --git a/src/Ombi.HealthChecks/HealthCheckExtensions.cs b/src/Ombi.HealthChecks/HealthCheckExtensions.cs index 89a350cfe..2b5dbb667 100644 --- a/src/Ombi.HealthChecks/HealthCheckExtensions.cs +++ b/src/Ombi.HealthChecks/HealthCheckExtensions.cs @@ -1,14 +1,17 @@ using Microsoft.Extensions.DependencyInjection; -using System; +using Ombi.HealthChecks.Checks; namespace Ombi.HealthChecks { public static class HealthCheckExtensions { - public static IHealthChecksBuilder AddOmbiHealthChecks(this IHealthChecksBuilder builder) { builder.AddCheck("Plex", tags: new string[] { "MediaServer" }); + builder.AddCheck("Emby", tags: new string[] { "MediaServer" }); + builder.AddCheck("Lidarr", tags: new string[] { "DVR" }); + builder.AddCheck("Sonarr", tags: new string[] { "DVR" }); + builder.AddCheck("Radarr", tags: new string[] { "DVR" }); return builder; } diff --git a/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj b/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj index 70b4dd959..9b75bfed5 100644 --- a/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj +++ b/src/Ombi.HealthChecks/Ombi.HealthChecks.csproj @@ -9,7 +9,11 @@ + + + + diff --git a/src/Ombi.HealthChecks/PlexHealthCheck.cs b/src/Ombi.HealthChecks/PlexHealthCheck.cs deleted file mode 100644 index 7015d9965..000000000 --- a/src/Ombi.HealthChecks/PlexHealthCheck.cs +++ /dev/null @@ -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 _settings; - public PlexHealthCheck(IPlexApi plexApi, ISettingsService settings) - { - _plexApi = plexApi; - _settings = settings; - } - public async Task 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>(); - 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); - } - } - } -} diff --git a/src/Ombi/.gitignore b/src/Ombi/.gitignore index 49c402ee8..d28f49b37 100644 --- a/src/Ombi/.gitignore +++ b/src/Ombi/.gitignore @@ -7,4 +7,4 @@ wwwroot/dist /connect.lock /coverage/* /Logs/** -**.db +**.db \ No newline at end of file diff --git a/src/Ombi/HealthCheck.css b/src/Ombi/HealthCheck.css new file mode 100644 index 000000000..bcdfe4d06 --- /dev/null +++ b/src/Ombi/HealthCheck.css @@ -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; +} \ No newline at end of file diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index 4f80b91c9..ea748694f 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -98,6 +98,12 @@ + + + Always + + + diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 57f72be0e..0b86d9000 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -218,7 +218,10 @@ namespace Ombi Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); - endpoints.MapHealthChecksUI(); + endpoints.MapHealthChecksUI(opts => + { + opts.AddCustomStylesheet("HealthCheck.css"); + }); }); app.UseSpa(spa => diff --git a/src/Ombi/healthchecksdb b/src/Ombi/healthchecksdb index 8b2c7dd717f6a6481c1253ae1b95bcc66b489187..90c88cbb9adad8ec62732eb991a380463829d580 100644 GIT binary patch delta 345 zcmZp8z|`=7X~SKAMvl$*{BQ7UnpqiHTA3K?Sy-Bx8e5te85kMp8W`ysnkyKZSs5Ex znHuXESQwgEnryxwuPPwI!FP^<{}KNY{w4g`{NDU3d_VclZ59;R#>b?|F*&_nnZv-s z*u>IOlYR0e5XaQgz{FUUZSvlFg?ckXO9KlzR(1wSMh0EZpv08Kq9P^(11m7nGcYx< zG&MIcX93CE>v9I?=YixQltN~)LSBA}LUMjyT4s7_QEG}FLZg9!fr+Vs95d8lpG-7^ zP0Wmp3`}ICnb;XbK{mVQCRHNYYhYkxIQc=n6q}*3k)@f%rUn+EFZpjW@c-fe&i{%3 lE&mJt$NcyBZvuUJkY9v_nUj$NM6iPhHW0zO`R#mR0RZ?5Rz3g# delta 208 zcmZp8z|`=7X~SKAMwZR@{BQ7UnphbbTbUT@8CV#b8W|cJ85kMp8W`ysnkyIrrA)01 z4fV_{Oe`!dH{Xv}72sjvPi5eL#J`(=0)OgeK>mCZdd%x|{(ysTE8hLLswQ zAuqo~Avr%UEwi*JHAT