From 1751305064176d2c0135f867773ccc46b03915ec Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 20 Apr 2023 15:26:43 +0100 Subject: [PATCH] fix(healthchecks): Removed redundant ping check --- .../Checks/OmbiPingHealthCheck.cs | 47 ------------------- .../Checks/OmbiPingHealthCheckOptions.cs | 16 ------- .../Checks/PlexHealthCheck.cs | 2 +- .../HealthCheckExtensions.cs | 31 ------------ 4 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 src/Ombi.HealthChecks/Checks/OmbiPingHealthCheck.cs delete mode 100644 src/Ombi.HealthChecks/Checks/OmbiPingHealthCheckOptions.cs diff --git a/src/Ombi.HealthChecks/Checks/OmbiPingHealthCheck.cs b/src/Ombi.HealthChecks/Checks/OmbiPingHealthCheck.cs deleted file mode 100644 index 726d020788..0000000000 --- a/src/Ombi.HealthChecks/Checks/OmbiPingHealthCheck.cs +++ /dev/null @@ -1,47 +0,0 @@ -using HealthChecks.Network; -using Microsoft.Extensions.Diagnostics.HealthChecks; -using System; -using System.Collections.Generic; -using System.Net.NetworkInformation; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Ombi.HealthChecks.Checks -{ - public class OmbiPingHealthCheck - : IHealthCheck - { - private readonly OmbiPingHealthCheckOptions _options; - public OmbiPingHealthCheck(OmbiPingHealthCheckOptions options) - { - _options = options ?? throw new ArgumentNullException(nameof(options)); - } - public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) - { - var configuredHosts = _options.ConfiguredHosts.Values; - - try - { - foreach (var (host, timeout, status) in configuredHosts) - { - using (var ping = new Ping()) - { - var pingReply = await ping.SendPingAsync(host, timeout); - - if (pingReply.Status != IPStatus.Success) - { - return new HealthCheckResult(status, description: $"Ping check for host {host} is failed with status reply:{pingReply.Status}"); - } - } - } - - return HealthCheckResult.Healthy(); - } - catch (Exception ex) - { - return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); - } - } - } -} diff --git a/src/Ombi.HealthChecks/Checks/OmbiPingHealthCheckOptions.cs b/src/Ombi.HealthChecks/Checks/OmbiPingHealthCheckOptions.cs deleted file mode 100644 index f89c71a522..0000000000 --- a/src/Ombi.HealthChecks/Checks/OmbiPingHealthCheckOptions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.Extensions.Diagnostics.HealthChecks; -using System.Collections.Generic; - -namespace Ombi.HealthChecks.Checks -{ - public class OmbiPingHealthCheckOptions - { - internal Dictionary ConfiguredHosts { get; } = new Dictionary(); - - public OmbiPingHealthCheckOptions AddHost(string host, int timeout, HealthStatus status) - { - ConfiguredHosts.Add(host, (host, timeout, status)); - return this; - } - } -} diff --git a/src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs b/src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs index 182c1b2f84..bc90c47569 100644 --- a/src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs +++ b/src/Ombi.HealthChecks/Checks/PlexHealthCheck.cs @@ -27,7 +27,7 @@ public override async Task CheckHealthAsync( var settings = await settingsProvider.GetSettingsAsync(); if (settings == null) { - return HealthCheckResult.Healthy("Plex is not confiured."); + return HealthCheckResult.Healthy("Plex is not configured."); } var taskResult = new List>(); diff --git a/src/Ombi.HealthChecks/HealthCheckExtensions.cs b/src/Ombi.HealthChecks/HealthCheckExtensions.cs index 2f80378ff1..21b9d5dde6 100644 --- a/src/Ombi.HealthChecks/HealthCheckExtensions.cs +++ b/src/Ombi.HealthChecks/HealthCheckExtensions.cs @@ -18,39 +18,8 @@ public static IHealthChecksBuilder AddOmbiHealthChecks(this IHealthChecksBuilder builder.AddCheck("Radarr", tags: new string[] { "DVR" }); builder.AddCheck("CouchPotato", tags: new string[] { "DVR" }); builder.AddCheck("SickRage", tags: new string[] { "DVR" }); - builder.AddOmbiPingHealthCheck(options => - { - options.AddHost("www.google.co.uk", 5000, HealthStatus.Unhealthy); - options.AddHost("www.google.com", 3000, HealthStatus.Degraded); - }, "External Ping", tags: new string[] { "System" }); return builder; } - - /// - /// Add a health check for network ping. - /// - /// The . - /// The action to configure the ping parameters. - /// The health check name. Optional. If null the type name 'ping' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional System.TimeSpan representing the timeout of the check. - /// The . - public static IHealthChecksBuilder AddOmbiPingHealthCheck(this IHealthChecksBuilder builder, Action setup, string name = default, HealthStatus? failureStatus = default, IEnumerable tags = default, TimeSpan? timeout = default) - { - var options = new OmbiPingHealthCheckOptions(); - setup?.Invoke(options); - - return builder.Add(new HealthCheckRegistration( - name, - sp => new OmbiPingHealthCheck(options), - failureStatus, - tags, - timeout)); - } } }