using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Ombi.HealthChecks.Checks; using System; using System.Collections.Generic; 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("Jellyfin", 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" }); 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)); } } }