/// <summary> /// Add a health check for IbmMQ services using a managed connection. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="queueManager">The name of the queue manager to use.</param> /// <param name="channel">The name of the channel.</param> /// <param name="connectionInfo">The connection information in the following format HOSTNAME(PORT).</param> /// <param name="userName">The user name. Optional.</param> /// <param name="password">The password. Optional</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'ibmmq' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddIbmMQManagedConnection( this IHealthChecksBuilder builder, string queueManager, string channel, string connectionInfo, string?userName = null, string?password = null, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { return(builder.Add(new HealthCheckRegistration( name ?? NAME, new IbmMQHealthCheck(queueManager, BuildProperties(channel, connectionInfo, userName, password)), failureStatus, tags, timeout))); }
/// <summary> /// Adds a new type activated health check with the specified name and implementation. /// </summary> /// <typeparam name="T">The health check implementation type.</typeparam> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="name">The name of the health check.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value /// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter health checks.</param> /// <param name="args">Additional arguments to provide to the constructor.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> /// <remarks> /// This method will use <see cref="ActivatorUtilities.CreateInstance{T}(IServiceProvider, object[])"/> to create the health check /// instance when needed. Additional arguments can be provided to the constructor via <paramref name="args"/>. /// </remarks> public static IHealthChecksBuilder AddTypeActivatedCheck <T>( this IHealthChecksBuilder builder, string name, HealthStatus?failureStatus, IEnumerable <string> tags, params object[] args) where T : class, IHealthCheck { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } return(builder.Add(new HealthCheckRegistration(name, s => ActivatorUtilities.CreateInstance <T>(s, args), failureStatus, tags))); }
/// <summary> /// Add a health check for Elasticsearch databases. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="elasticsearchUri">The Elasticsearch connection string to be used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'elasticsearch' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddElasticsearch( this IHealthChecksBuilder builder, string elasticsearchUri, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { var options = new ElasticsearchOptions(); options.UseServer(elasticsearchUri); return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new ElasticsearchHealthCheck(options), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for AWS DynamoDb database. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup">The action to configure the DynamoDb connection parameters.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'dynamodb' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddDynamoDb( this IHealthChecksBuilder builder, Action <DynamoDBOptions>?setup, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { var options = new DynamoDBOptions(); setup?.Invoke(options); return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new DynamoDbHealthCheck(options), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for SendGrid. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="apiKey">The API key.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'sendgrid' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddSendGrid( this IHealthChecksBuilder builder, string apiKey, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { var registrationName = name ?? NAME; builder.Services.AddHttpClient(registrationName); return(builder.Add(new HealthCheckRegistration( registrationName, sp => new SendGridHealthCheck(apiKey, sp.GetRequiredService <IHttpClientFactory>()), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for single uri. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="uri">The uri to check.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'uri-group' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns></param> public static IHealthChecksBuilder AddUrlGroup(this IHealthChecksBuilder builder, Uri uri, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { builder.Services.AddHttpClient(); var registrationName = name ?? NAME; return(builder.Add(new HealthCheckRegistration( registrationName, sp => { var options = new UriHealthCheckOptions() .AddUri(uri); return CreateHealthCheck(sp, registrationName, options); }, failureStatus, tags, timeout))); }
/// <summary> /// Add a Healthcheck to resolve a hostname and verify the number of resolved address is within the configured minimum and maximum /// </summary> /// <remarks> /// Add host configurations using setup.ResolveHost(host).To(registrations); /// </remarks> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup">Action to add hosts and configure minimum and maximum resolved addresses</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'dns' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddDnsResolveHostCountHealthCheck(this IHealthChecksBuilder builder, Action <DnsResolveCountOptions> setup, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default) { var options = new DnsResolveCountOptions(); setup?.Invoke(options); if (!options.HostRegistrations.Any()) { throw new ArgumentNullException(nameof(options), "No dns hosts have been registered"); } return(builder.Add(new HealthCheckRegistration( name ?? DNS_COUNT_NAME, sp => new DnsResolveHostCountHealthCheck(options), failureStatus, tags))); }
/// <summary> /// Add a health check for ArangoDB. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="connectionOptionsFactory">A factory to build the ArangoDB connection data to use.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'arangodb' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddArangoDb(this IHealthChecksBuilder builder, Func <IServiceProvider, ArangoDbOptions> connectionOptionsFactory, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { if (connectionOptionsFactory == null) { throw new ArgumentNullException(nameof(connectionOptionsFactory)); } return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new ArangoDbHealthCheck(connectionOptionsFactory(sp)), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for specified Azure Digital Twin existing models. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="clientId">The azure digital twin client id.</param> /// <param name="clientSecret">The azure digital twin client secret.</param> /// <param name="tenantId">The azure digital twin tenant id.</param> /// <param name="hostName">The azure digital host uri.</param> /// <param name="models">The azure digital twin model collection expected.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'azureeventhub' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddAzureDigitalTwinModels( this IHealthChecksBuilder builder, string clientId, string clientSecret, string tenantId, string hostName, string[] models, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { return(builder.Add(new HealthCheckRegistration( name ?? AZUREDIGITALTWINMODELS_NAME, sp => new AzureDigitalTwinModelsHealthCheck(clientId, clientSecret, tenantId, hostName, models), failureStatus, tags, timeout))); }
/// <summary> /// Adds a new health check with the specified name and implementation. /// </summary> /// <typeparam name="T">The health check implementation type.</typeparam> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="name">The name of the health check.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value /// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter health checks.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> /// <remarks> /// This method will use <see cref="ActivatorUtilities.GetServiceOrCreateInstance{T}(IServiceProvider)"/> to create the health check /// instance when needed. If a service of type <typeparamref name="T"/> is registered in the dependency injection container /// with any lifetime it will be used. Otherwise an instance of type <typeparamref name="T"/> will be constructed with /// access to services from the dependency injection container. /// </remarks> public static IHealthChecksBuilder AddCheck <T>( this IHealthChecksBuilder builder, string name, HealthStatus?failureStatus = null, IEnumerable <string>?tags = null, TimeSpan?timeout = null) where T : class, IHealthCheck { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } return(builder.Add(new HealthCheckRegistration(name, s => ActivatorUtilities.GetServiceOrCreateInstance <T>(s), failureStatus, tags, timeout))); }
/// <summary> /// Add the Kubernetes Health Check /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup">Action to configure Kubernetes cluster and registrations</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'k8s' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddKubernetes(this IHealthChecksBuilder builder, Action <KubernetesHealthCheckBuilder> setup, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default) { var kubernetesHealthCheckBuilder = new KubernetesHealthCheckBuilder(); setup?.Invoke(kubernetesHealthCheckBuilder); if (kubernetesHealthCheckBuilder.Configuration == null) { throw new ArgumentNullException(nameof(kubernetesHealthCheckBuilder.Configuration)); } var client = new Kubernetes(kubernetesHealthCheckBuilder.Configuration); var kubernetesChecksExecutor = new KubernetesChecksExecutor(client); return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new KubernetesHealthCheck(kubernetesHealthCheckBuilder, kubernetesChecksExecutor), failureStatus, tags))); }
/// <summary> /// Add a healthcheck that allows to check a predicate against the configured process name. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="processName">The name of the process</param> /// <param name="predicate">Process[] predicate to configure checks</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'process' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddProcessHealthCheck( this IHealthChecksBuilder builder, string processName, Func <Process[], bool> predicate, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { if (string.IsNullOrEmpty(processName)) { throw new ArgumentNullException(nameof(processName)); } if (predicate is null) { throw new ArgumentNullException(nameof(predicate)); } return(builder.Add(new HealthCheckRegistration( name ?? PROCESS_NAME, sp => new ProcessHealthCheck(processName, predicate), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for Solr databases. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="solrUri">The Solr connection string to be used.</param> /// <param name="solrCore"></param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'solr' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddSolr( this IHealthChecksBuilder builder, string solrUri, string solrCore, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { var options = new SolrOptions(); options.UseServer(solrUri, solrCore, timeout: null); return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new SolrHealthCheck(options), failureStatus, tags, timeout))); }
public static IHealthChecksBuilder AddGithub(this IHealthChecksBuilder builder, Action <GithubApiHealthCheckOptions> uriOptions, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default) { builder.Services.AddHttpClient(); builder.Services.Configure(uriOptions); builder.Services.AddScoped <GithubApiHealthCheck>(); return(builder.Add(new HealthCheckRegistration ( name ?? NAME, sp => sp.GetRequiredService <GithubApiHealthCheck>(), failureStatus, tags ))); }
/// <summary> /// Add a health check for multiple uri's. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="uris">The collection of uri's to be checked.</param> /// <param name="httpMethod">The http method to be used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'uri-group' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns></param> public static IHealthChecksBuilder AddUrlGroupWithVersioning(this IHealthChecksBuilder builder, IEnumerable <Uri> uris, HttpMethod httpMethod, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { builder.Services.AddHttpClient(); var registrationName = name ?? NAME; return(builder.Add(new HealthCheckRegistration( registrationName, sp => { var options = UriHealthCheckOptions .CreateFromUris(uris) .UseHttpMethod(httpMethod); return CreateHealthCheck(sp, registrationName, options); }, failureStatus, tags, timeout))); }
/// <summary> /// Adds a healthcheck that allows to check the allocated bytes in memory and configure a threshold /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="maximumMegabytesAllocated">The maximum megabytes allowed to be allocated by the process</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'process' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddProcessAllocatedMemoryHealthCheck( this IHealthChecksBuilder builder, int maximumMegabytesAllocated, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { if (maximumMegabytesAllocated <= 0) { throw new ArgumentException($"{nameof(maximumMegabytesAllocated)} should be greater than zero"); } return(builder.Add(new HealthCheckRegistration( name ?? PROCESS_ALLOCATED_MEMORY, sp => new ProcessAllocatedMemoryHealthCheck(maximumMegabytesAllocated), failureStatus, tags, timeout))); }
public static IHealthChecksBuilder AddMigrationSqlServerCheck <TContext>( this IHealthChecksBuilder builder, EntityFrameworkConfiguration dbConfiguration, string migrationAssembly, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default) where TContext : GspDbContext { var lastMigrationName = DbContextHelper.GetLastDbContextMigrationName <TContext>( dbConfiguration.ConnectionString, migrationAssembly); return(builder.Add(new HealthCheckRegistration( name ?? nameof(MigrationSqlServerHealthCheck), sp => new MigrationSqlServerHealthCheck(dbConfiguration.ConnectionString, lastMigrationName), failureStatus, tags))); }
/// <summary> /// Add a health check for Azure IoT Hub. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="optionsFactory">A action to configure the Azure IoT Hub connection to use.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'iothub' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddAzureIoTHub(this IHealthChecksBuilder builder, Action <IoTHubOptions> optionsFactory, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { var options = new IoTHubOptions(); optionsFactory?.Invoke(options); var registrationName = name ?? NAME; return(builder.Add(new HealthCheckRegistration( registrationName, sp => new IoTHubHealthCheck(options), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for multiple uri's. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="uris">The collection of uri's to be checked.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'uri-group' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <param name="configureClient">An optional setup action to configure the Uris HealthCheck http client</param> /// <param name="configureHttpMessageHandler">An optional setup action to configure the Uris HealthCheck http client message handler</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddUrlGroup( this IHealthChecksBuilder builder, IEnumerable <Uri> uris, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default, Action <IServiceProvider, HttpClient>?configureClient = null, Func <IServiceProvider, HttpMessageHandler>?configureHttpMessageHandler = null) { var registrationName = name ?? NAME; ConfigureUrisClient(builder, configureClient, configureHttpMessageHandler, registrationName); return(builder.Add(new HealthCheckRegistration( registrationName, sp => CreateHealthCheck(sp, registrationName, UriHealthCheckOptions.CreateFromUris(uris)), failureStatus, tags, timeout))); }
/// <summary> /// Creates a healthcheck that with the specified filter /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IHealthChecksBuilder AddLoggerHealthCheckForType <T>(IHealthChecksBuilder builder, string?name, Action <LoggerHealthCheckOptions>?setup, IEnumerable <string>?tags, HealthStatus failureStatus, Func <LogEntry, bool> typeFilter) { var options = new LoggerHealthCheckOptions(); setup?.Invoke(options); if (options.Filter != Filters.DefaultHealthCheck) { var customFilter = options.Filter; options.Filter = Filters.Combine(customFilter, typeFilter); } else { options.Filter = typeFilter; } return(builder.Add(new HealthCheckRegistration( name ?? typeof(T).Name, sp => new LoggerHealthCheck.LoggerHealthCheck(sp.GetRequiredService <HealthCheckLoggerProvider>(), sp.GetRequiredService <IHealthMessageFormatter>(), options), failureStatus, tags))); }
/// <summary> /// Add a health check for Kafka cluster. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup">The action to configure the kafka connection configuration parameters to be used.</param> /// <param name="topic">The topic name to produce kafka messages on. Optional. If <c>null</c> the topic default 'healthcheck-topic' will be used for the name.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'kafka' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddKafka( this IHealthChecksBuilder builder, Action <ProducerConfig> setup, string?topic = default, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { var config = new ProducerConfig(); setup?.Invoke(config); return(builder.Add(new HealthCheckRegistration( name ?? NAME, new KafkaHealthCheck(config, topic), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for SignalR. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="url">The SignalR hub url to be used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'signalr' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddSignalRHub( this IHealthChecksBuilder builder, string url, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { Func <HubConnection> hubConnectionBuilder = () => new HubConnectionBuilder() .WithUrl(url) .Build(); return(builder.Add( new HealthCheckRegistration( name ?? NAME, sp => new SignalRHealthCheck(hubConnectionBuilder), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for TDengine services. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="connectionStringFactory">A factory to build the TDengine connection string to use.</param> /// <param name="healthQuery">The query to be executed.Optional. If <c>null</c> select 1 is used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'TDengine' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddTDengine(this IHealthChecksBuilder builder, Func <IServiceProvider, string> connectionStringFactory, string healthQuery = default, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { if (connectionStringFactory == null) { throw new ArgumentNullException(nameof(connectionStringFactory)); } return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new TaosHealthCheck(connectionStringFactory(sp), healthQuery ?? HEALTH_QUERY), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for Elasticsearch databases. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup">The Elasticsearch option setup.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'elasticsearch' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddElasticsearch( this IHealthChecksBuilder builder, Action <ElasticsearchOptions>?setup, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { var options = new ElasticsearchOptions(); setup?.Invoke(options); options.RequestTimeout ??= timeout; return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new ElasticsearchHealthCheck(options), failureStatus, tags, timeout))); }
public static IHealthChecksBuilder AddServiceClient <T>( this IHealthChecksBuilder builder, string name = null, string route = "naos/echo", HealthStatus?failureStatus = null, IEnumerable <string> tags = null) where T : ServiceDiscoveryClient { name ??= typeof(T).Name; if (name.EndsWith("Client", StringComparison.OrdinalIgnoreCase)) { name = name.Replace("Client", "-serviceclient", StringComparison.OrdinalIgnoreCase); } return(builder.Add( new HealthCheckRegistration( name, sp => CreateHealthCheck <T>(sp, route), failureStatus, tags))); }
/// <summary> /// Add a health check for multiple uri's. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="uriOptions">The action used to configured uri values and specified http methods to be checked.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'uri-group' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <param name="configureClient">An optional setup action to configure the Uris HealthCheck http client</param> /// <param name="configureHttpMessageHandler">An optional setup action to configure the Uris HealthCheck http client message handler</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddUrlGroup(this IHealthChecksBuilder builder, Action <UriHealthCheckOptions> uriOptions, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default, Action <IServiceProvider, HttpClient> configureClient = null, Func <IServiceProvider, HttpMessageHandler> configureHttpMessageHandler = null) { var registrationName = name ?? NAME; ConfigureUrisClient(builder, configureClient, configureHttpMessageHandler, registrationName); return(builder.Add(new HealthCheckRegistration( registrationName, sp => { var options = new UriHealthCheckOptions(); uriOptions?.Invoke(options); return CreateHealthCheck(sp, registrationName, options); }, failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for Azure Key Vault. Default behaviour is using Managed Service Identity, to use Client Secrets call UseClientSecrets in setup action /// </summary> /// <param name="keyVaultServiceUri">The AzureKeyVault service uri.</param> /// <param name="credential">The TokenCredentail to use, you can use Azure.Identity with DefaultAzureCredential or other kind of TokenCredential,you can read more on <see href="https://github.com/Azure/azure-sdk-for-net/blob/Azure.Identity_1.2.2/sdk/identity/Azure.Identity/README.md"/>. </param> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup"> Setup action to configure Azure Key Vault options.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'azurekeyvault' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional System.TimeSpan representing the timeout of the check.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns> public static IHealthChecksBuilder AddAzureKeyVault(this IHealthChecksBuilder builder, Uri keyVaultServiceUri, TokenCredential credential, Action <AzureKeyVaultOptions> setup, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default, TimeSpan?timeout = default) { var options = new AzureKeyVaultOptions(); setup?.Invoke(options); if (keyVaultServiceUri == null) { throw new ArgumentNullException(nameof(keyVaultServiceUri)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } return(builder.Add(new HealthCheckRegistration( name ?? KEYVAULT_NAME, sp => new AzureKeyVaultHealthCheck(keyVaultServiceUri, credential, options), failureStatus, tags, timeout))); }
/// <summary> /// Add a health check for SqlServer services. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="connectionStringFactory">A factory to build the SQL Server connection string to use.</param> /// <param name="healthQuery">The query to be executed.Optional. If <c>null</c> select 1 is used.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'sqlserver' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <param name="beforeOpenConnectionConfigurer">An optional action executed before the connection is Open on the healthcheck.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddSqlServer( this IHealthChecksBuilder builder, Func <IServiceProvider, string> connectionStringFactory, string?healthQuery = default, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default, Action <SqlConnection>?beforeOpenConnectionConfigurer = default) { if (connectionStringFactory == null) { throw new ArgumentNullException(nameof(connectionStringFactory)); } return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new SqlServerHealthCheck(connectionStringFactory(sp), healthQuery ?? HEALTH_QUERY, beforeOpenConnectionConfigurer), failureStatus, tags, timeout))); }
public static IServiceCollection UseHybridServiceStatus(this IServiceCollection services, params Assembly[] assemblies) { services.UseServiceStatus(assemblies); IHealthChecksBuilder healthChecksBuilder = services.AddHealthChecks(); foreach (ServiceDescriptor descriptor in services.Where(d => d.ServiceType == typeof(IServiceStatusCheck)).ToList()) { if (descriptor.ServiceType == typeof(IServiceStatusCheck)) { PropertyInfo nameProperty = descriptor.ImplementationType.GetProperty("HealthName"); if (nameProperty == null || nameProperty.GetMethod == null || !nameProperty.GetMethod.IsStatic) { throw new ApplicationException($"{descriptor.ImplementationType.Name} does not have a public static property HealthName with a getter"); } healthChecksBuilder.Add(new HealthCheckRegistration((string)nameProperty.GetValue(null), (IServiceProvider s) => (IHealthCheck)s.GetServices <IServiceStatusCheck>().First(x => x.GetType() == descriptor.ImplementationType), null, null)); } } return(services); }
/// <summary> /// Add a health check for Azure Service Bus Subscription. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="endpointFactory">A factory to build the azure service bus endpoint to be used, format sb://myservicebus.servicebus.windows.net/.</param> /// <param name="topicNameFactory">A factory to build the topic name of the topic to check.</param> /// <param name="subscriptionNameFactory">A factory to build the subscription name of the topic to check.</param> /// <param name="tokenCredentialFactory">A factory to build the token credential for auth.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'azuretopic' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param> /// <returns>The specified <paramref name="builder"/>.</returns> public static IHealthChecksBuilder AddAzureServiceBusSubscription( this IHealthChecksBuilder builder, Func <IServiceProvider, string> endpointFactory, Func <IServiceProvider, string> topicNameFactory, Func <IServiceProvider, string> subscriptionNameFactory, Func <IServiceProvider, TokenCredential> tokenCredentialFactory, string?name = default, HealthStatus?failureStatus = default, IEnumerable <string>?tags = default, TimeSpan?timeout = default) { if (endpointFactory == null) { throw new ArgumentNullException(nameof(endpointFactory)); } if (topicNameFactory == null) { throw new ArgumentNullException(nameof(topicNameFactory)); } if (subscriptionNameFactory == null) { throw new ArgumentNullException(nameof(subscriptionNameFactory)); } if (tokenCredentialFactory == null) { throw new ArgumentNullException(nameof(tokenCredentialFactory)); } return(builder.Add(new HealthCheckRegistration( name ?? AZURESUBSCRIPTION_NAME, sp => new AzureServiceBusSubscriptionHealthCheck( endpointFactory(sp), topicNameFactory(sp), subscriptionNameFactory(sp), tokenCredentialFactory(sp)), failureStatus, tags, timeout))); }