Example #1
0
        protected internal override void SetMonitoring()
        {
            if (string.IsNullOrEmpty(this.HealthCheck.FullClassName))
            {
                HealthChecksBuilder.AddAsyncCheck(Name, () =>
                {
                    return(CustomCheck != null ? CustomCheck() : Task.FromResult(HealthCheckResult.Healthy()));
                });
            }

            else
            {
                Type       classType  = null;
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (Assembly assem in assemblies)
                {
                    classType = assem.GetType(HealthCheck.FullClassName);
                    if (classType != null)
                    {
                        break;
                    }
                }

                if (classType == null)
                {
                    throw new Exception(
                              $"Invalid class name {HealthCheck.FullClassName} defined in custom test named {Name}");
                }

                var classInstance = ActivatorUtilities.CreateInstance(_serviceProvider, classType) as IHealthCheck;
                HealthChecksBuilder.AddCheck(Name, classInstance);
            }
        }
        public static IHealthChecksBuilder AddHealthChecks(this IMetricsBuilder metricsBuilder,
                                                           Action <IHealthChecksBuilder> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var services = metricsBuilder.Services;

            var store    = new InMemoryHealthChecksStore();
            var host     = new HealthChecksHost(store);
            var registry = new InMemoryHealthChecksRegistry();

            registry.Add(host);

            services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksRegistry>(r => registry));
            services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksStore, InMemoryHealthChecksStore>(r => store));
            services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksHost, HealthChecksHost>(r => host));
            services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksStore>(r => new InMemoryHealthChecksStore()));

            var healthChecksBuilder = new HealthChecksBuilder(metricsBuilder.Services);

            configure(healthChecksBuilder);

            return(healthChecksBuilder);
        }
Example #3
0
        public void ShoudlReturnTrueIfNoNeedValidation()
        {
            var builder = new HealthChecksBuilder();
            var sut     = new AuthenticationService(builder);

            var act = sut.NeedAuthentication();

            Assert.True(act == false);
        }
Example #4
0
        public void ShoudlReturnTrueIfNeedValidation()
        {
            var builder = new HealthChecksBuilder().UseAuthorization("AnyApiKey");
            var sut     = new AuthenticationService(builder);

            var act = sut.NeedAuthentication();

            Assert.True(act == true);
        }
Example #5
0
        public void ShouldReturnTrueIfNoNeedValidation()
        {
            var customConfig = new HealthChecksBuilder()
                               .HealthCheckConfig;

            var sut = new AuthenticationService(customConfig);
            var act = sut.NeedAuthentication();

            Assert.False(act);
        }
        protected internal override void SetMonitoring()
        {
            var connectionFactory = new RabbitMQ.Client.ConnectionFactory();

            connectionFactory.Uri = new Uri(HealthCheck.EndpointOrHost);

            HealthChecksBuilder.AddRabbitMQ(provider =>
            {
                return(connectionFactory);
            }, Name, HealthStatus.Unhealthy);
        }
Example #7
0
        public async Task ShouldReturnErrorIfValidationFails()
        {
            var hcCustomBuilder = new HealthChecksBuilder().UseAuthorization("AnotherApiKey");

            var sut = new AuthenticationHandler(hcCustomBuilder.HealthCheckConfig, _mockAuthService.Object);
            var act = await sut.HandleRequest(_httpRequestFake, default);

            string json = JsonConvert.SerializeObject(new ForbiddenError(_wrongApiKey).HttpErrorResponse, hcCustomBuilder.HealthCheckConfig.SerializerSettings);

            Assert.Equal(HttpStatusCode.Forbidden, act.StatusCode);
            Assert.Equal(json, await act.Content.ReadAsStringAsync());
        }
Example #8
0
        protected internal override void SetMonitoring()
        {
            HealthChecksBuilder.AddHangfire(options =>
            {
                var minimumAvailableServers =
                    this.HealthCheck.HealthCheckConditions.HangfireBehaviour?.MinimumAvailableServers;

                var maximumJobsFailed =
                    this.HealthCheck.HealthCheckConditions.HangfireBehaviour?.MinimumAvailableServers;

                options.MinimumAvailableServers = minimumAvailableServers;

                options.MaximumJobsFailed = maximumJobsFailed;
            }, this.HealthCheck.Name);
        }
 public AuthenticationHandler(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder) : base(httpConfiguration, healthChecksBuilder)
 {
 }
 protected HealthHandlerBase(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder)
 {
     _httpConfiguration  = httpConfiguration;
     HealthChecksBuilder = healthChecksBuilder;
 }
 public DependencyHandler(HttpConfiguration httpConfig, HealthChecksBuilder builder)
 {
     _httpConfig = httpConfig;
     _hcBuilder  = builder;
 }
Example #12
0
 public HealthUiHandler(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder) : base(
         httpConfiguration, healthChecksBuilder)
 {
 }
 public HealthCheckService(HealthChecksBuilder healthChecksBuilder)
 {
     _healthChecksBuilder = healthChecksBuilder;
 }
Example #14
0
 public HealthCheckHandler(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder) : base(httpConfiguration, healthChecksBuilder)
 {
     //criar serviço aqui por injeção e uma interface pro serviço
 }
Example #15
0
 protected internal override void SetMonitoring()
 {
     HealthChecksBuilder.AddSqlServer(this.HealthCheck.ConnectionString,
                                      this.HealthCheck.HealthCheckConditions.SqlBehaviour?.Query);
 }