public static IHealthChecksBuilder AddDependencies( this IHealthChecksBuilder builder, List <Dependency> dependencies) { foreach (var dependencia in dependencies) { string nomeDependencia = dependencia.Name.ToLower(); if (nomeDependencia.StartsWith("sqlserver-")) { builder = builder.AddSqlServer(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("url-")) { builder = builder.AddUrlGroup(new Uri(dependencia.Url), name: dependencia.Name); } else if (nomeDependencia.StartsWith("azureblobstorage-")) { builder = builder.AddAzureBlobStorage(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("sqljob-")) { SqlJobHealthCheck sqlJob = new SqlJobHealthCheck(dependencia.ConnectionString, nomeDependencia.Replace("sqljob-", "")); builder = builder.AddCheck(nomeDependencia, sqlJob); } } return(builder); }
public static IHealthChecksBuilder AddDependencies( this IHealthChecksBuilder builder, List <Dependency> dependencies) { foreach (var dependencia in dependencies) { string nomeDependencia = dependencia.Name.ToLower(); if (nomeDependencia.StartsWith("sqlserver-")) { builder = builder.AddSqlServer(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("mongodb-")) { builder = builder.AddMongoDb(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("redis-")) { builder = builder.AddRedis(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("postgres-")) { builder = builder.AddNpgSql(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("mysql-")) { builder = builder.AddMySql(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("url-")) { builder = builder.AddUrlGroup(new Uri(dependencia.Url), name: dependencia.Name); } else if (nomeDependencia.StartsWith("rabbitmq-")) { builder = builder.AddRabbitMQ(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("azureservicebusqueue-")) { builder = builder.AddAzureServiceBusQueue(dependencia.ConnectionString, queueName: dependencia.QueueName, name: dependencia.Name); } else if (nomeDependencia.StartsWith("azureblobstorage-")) { builder = builder.AddAzureBlobStorage(dependencia.ConnectionString, name: dependencia.Name); } else if (nomeDependencia.StartsWith("documentdb-")) { builder = builder.AddDocumentDb( docdb => { docdb.UriEndpoint = dependencia.UriEndpoint; docdb.PrimaryKey = dependencia.PrimaryKey; }); } } return(builder); }
public static IServiceCollection AddStorageManager(this IServiceCollection services, StorageOptions options, IHealthChecksBuilder healthChecksBuilder = null) { if (options.UsedAzure()) { services.AddAzureBlobStorageManager(options.Azure); if (healthChecksBuilder != null) { healthChecksBuilder.AddAzureBlobStorage( options.Azure.ConnectionString, containerName: options.Azure.Container, name: "Storage (Azure Blob)", failureStatus: HealthStatus.Degraded); } } else if (options.UsedAmazon()) { services.AddAmazonS3StorageManager(options.Amazon); if (healthChecksBuilder != null) { healthChecksBuilder.AddS3( s3 => { s3.AccessKey = options.Amazon.AccessKeyID; s3.SecretKey = options.Amazon.SecretAccessKey; s3.BucketName = options.Amazon.BucketName; s3.S3Config = new AmazonS3Config { RegionEndpoint = RegionEndpoint.GetBySystemName(options.Amazon.RegionEndpoint), }; }, name: "Storage (Amazon S3)", failureStatus: HealthStatus.Degraded); } } else if (options.UsedLocal()) { services.AddLocalStorageManager(options.Local); if (healthChecksBuilder != null) { healthChecksBuilder.AddFilePathWrite(options.Local.Path, name: "Storage (Local Directory)", failureStatus: HealthStatus.Degraded); } } else { services.AddFakeStorageManager(); } return(services); }
//public static IServiceCollection AddAppInsight(this IServiceCollection services, IConfiguration configuration) //{ // services.AddApplicationInsightsTelemetry(configuration); // //string orchestratorType = configuration.GetValue<string>("OrchestratorType"); // //if (orchestratorType?.ToUpper() == "K8S") // //{ // // // Enable K8s telemetry initializer // // services.EnableKubernetes(); // //} // //if (orchestratorType?.ToUpper() == "SF") // //{ // // // Enable SF telemetry initializer // // services.AddSingleton<ITelemetryInitializer>((serviceProvider) => // // new FabricTelemetryInitializer()); // //} // return services; //} public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) { string accountName = configuration.GetValue <string>("AzureStorageAccountName"); string accountKey = configuration.GetValue <string>("AzureStorageAccountKey"); string name = configuration.GetValue <string>("HealthCheck:Name"); IHealthChecksBuilder hcBuilder = services.AddHealthChecks(); if (!string.IsNullOrEmpty(name)) { hcBuilder .AddCheck(name, () => HealthCheckResult.Healthy()); } bool bDb = configuration.GetValue <bool>("HealthCheck:DB:Enable"); if (bDb) { string hcname = configuration.GetValue <string>("HealthCheck:DB:Name"); string[] tags = configuration.GetSection("HealthCheck:DB:tags").Get <string[]>(); hcBuilder .AddSqlServer( configuration["ConnectionString"], name: hcname, tags: tags); } bool bStorage = configuration.GetValue <bool>("HealthCheck:AzureBlobStorage:Enable"); if (bStorage && !string.IsNullOrEmpty(accountName) && !string.IsNullOrEmpty(accountKey)) { string hcname = configuration.GetValue <string>("HealthCheck:AzureBlobStorage:Name"); string[] tags = configuration.GetSection("HealthCheck:AzureBlobStorage:tags").Get <string[]>(); hcBuilder .AddAzureBlobStorage( $"DefaultEndpointsProtocol=https;AccountName={accountName};AccountKey={accountKey};EndpointSuffix=core.windows.net", name: hcname, tags: tags); } bool bService = configuration.GetValue <bool>("HealthCheck:AzureServiceBusTopic:Enable"); if (bService && configuration.GetValue <bool>("AzureServiceBusEnabled")) { string hcname = configuration.GetValue <string>("HealthCheck:AzureServiceBusTopic:Name"); string topic = configuration.GetValue <string>("HealthCheck:AzureServiceBusTopic:topicName"); string[] tags = configuration.GetSection("HealthCheck:AzureServiceBusTopic:tags").Get <string[]>(); hcBuilder .AddAzureServiceBusTopic( configuration["EventBusConnection"], topicName: topic, name: hcname, tags: tags); } bool bRabbit = configuration.GetValue <bool>("HealthCheck:RabbitMQ:Enable"); if (bRabbit && !configuration.GetValue <bool>("AzureServiceBusEnabled")) { string hcname = configuration.GetValue <string>("HealthCheck:RabbitMQ:Name"); string[] tags = configuration.GetSection("HealthCheck:RabbitMQ:tags").Get <string[]>(); hcBuilder .AddRabbitMQ( $"amqp://{configuration["EventBusConnection"]}", name: hcname, tags: tags); } return(services); }
public static IHealthChecksBuilder AddCustomAzureBlobStorage(this IHealthChecksBuilder builder, IConfiguration configuration) { return(builder.AddAzureBlobStorage(string.Join(';', configuration.GetAzureBlobStorageConnectionString().Split(';').Take(4)))); }