public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(MySqlLiveness)} is checking the MySql."); using (var connection = new MySqlConnection(_connectionString)) { await connection.OpenAsync(cancellationToken); if (!await connection.PingAsync(cancellationToken)) { _logger?.LogWarning($"The {nameof(MySqlLiveness)} check fail for {_connectionString}."); return(LivenessResult.UnHealthy($"The {nameof(MySqlLiveness)} check fail.")); } _logger?.LogInformation($"The {nameof(MySqlLiveness)} check success for {_connectionString}"); return(LivenessResult.Healthy()); } } catch (Exception ex) { _logger?.LogWarning($"The {nameof(MySqlLiveness)} check fail for {_connectionString} with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(KafkaLiveness)} is checking the Kafka broker."); using (var producer = new Producer <Null, string>(_configuration, null, new StringSerializer(Encoding.UTF8))) { var result = await producer.ProduceAsync("beatpulse-topic", null, $"Check Kafka healthy on {DateTime.UtcNow}"); if (result.Error.Code != ErrorCode.NoError) { _logger?.LogWarning($"The {nameof(KafkaLiveness)} check failed."); return(LivenessResult.UnHealthy($"ErrorCode {result.Error.Code} with reason ('{result.Error.Reason}')")); } _logger?.LogInformation($"The {nameof(KafkaLiveness)} check success."); return(LivenessResult.Healthy()); } } catch (Exception ex) { _logger?.LogWarning($"The {nameof(KafkaLiveness)} check fail for Kafka broker with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(TcpLiveness)} is checking hosts."); foreach (var(host, port) in _options.ConfiguredHosts) { using (var tcpClient = new TcpClient()) { await tcpClient.ConnectAsync(host, port); if (!tcpClient.Connected) { _logger?.LogWarning($"The {nameof(TcpLiveness)} check failed for host {host} and port {port}."); return(LivenessResult.UnHealthy($"Connection to host {host}:{port} failed")); } } } _logger?.LogInformation($"The {nameof(TcpLiveness)} check success."); return(LivenessResult.Healthy()); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(TcpLiveness)} check fail with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(AzureEventHubLiveness)} is checking the Azure Event Hub."); var connectionStringBuilder = new EventHubsConnectionStringBuilder(_connectionString) { EntityPath = _eventHubName }; var eventHubClient = EventHubClient .CreateFromConnectionString(connectionStringBuilder.ToString()); await eventHubClient.GetRuntimeInformationAsync(); _logger?.LogInformation($"The {nameof(AzureEventHubLiveness)} check success."); return(LivenessResult.Healthy()); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(AzureEventHubLiveness)} check fail for {_connectionString} with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { using (var producer = new Producer <Null, string>(_config, null, new StringSerializer(Encoding.UTF8))) { var result = await producer.ProduceAsync("beatpulse-topic", null, $"Check Kafka healthy on {DateTime.UtcNow}"); if (result.Error.Code != ErrorCode.NoError) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"ErrorCode {result.Error.Code} with reason ('{result.Error.Reason}')"; return(message, false); } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } }
public Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = new CancellationToken()) { try { var factory = new Rmq.Client.ConnectionFactory() { Uri = new Uri(_rabbitMqConnectionString) }; using (var connection = factory.CreateConnection()) { if (connection.IsOpen && connection.ServerProperties.Any()) { return(Task.FromResult((BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true))); } } return(Task.FromResult((BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, false))); } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(Task.FromResult((message, false))); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(DnsResolveLiveness)} is checking DNS entries."); foreach (var item in _options.ConfigureHosts.Values) { var ipAddresses = await Dns.GetHostAddressesAsync(item.Host); foreach (var ipAddress in ipAddresses) { if (!item.Resolutions.Contains(ipAddress.ToString())) { _logger?.LogWarning($"The {nameof(DnsResolveLiveness)} check fail for {ipAddress} was not resolved from host {item.Host}."); return(LivenessResult.UnHealthy("Ip Address {ipAddress} was not resolved from host {item.Host}")); } } } _logger?.LogInformation($"The {nameof(DnsResolveLiveness)} check success."); return(LivenessResult.Healthy()); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(DnsResolveLiveness)} check fail with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { var configuredHosts = _options.ConfiguredHosts.Values; try { _logger?.LogInformation($"{nameof(PingLiveness)} is checking hosts."); foreach (var(host, timeout) in configuredHosts) { using (var ping = new Ping()) { var pingReply = await ping.SendPingAsync(host, timeout); if (pingReply.Status != IPStatus.Success) { _logger?.LogWarning($"The {nameof(PingLiveness)} check failed for host {host} is failed with status reply:{pingReply.Status}."); return(LivenessResult.UnHealthy($"Ping check for host {host} is failed with status reply:{pingReply.Status}")); } } } _logger?.LogInformation($"The {nameof(PingLiveness)} check success."); return(LivenessResult.Healthy()); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(PingLiveness)} check fail with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(IdSvrLiveness)} is checking the IdSvr on {_idSvrUri}."); using (var httpClient = new HttpClient() { BaseAddress = _idSvrUri }) { var response = await httpClient.GetAsync(IDSVR_DISCOVER_CONFIGURATION_SEGMENT); if (!response.IsSuccessStatusCode) { _logger?.LogWarning($"The {nameof(IdSvrLiveness)} check failed for server {_idSvrUri}."); return(LivenessResult.UnHealthy("Discover endpoint is not responding with 200 OK, the current status is {response.StatusCode} and the content { (await response.Content.ReadAsStringAsync())}")); } _logger?.LogInformation($"The {nameof(IdSvrLiveness)} check success."); return(LivenessResult.Healthy()); } } catch (Exception ex) { _logger?.LogWarning($"The {nameof(IdSvrLiveness)} check fail for IdSvr with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = new CancellationToken()) { try { _logger?.LogInformation($"{nameof(RabbitMQLiveness)} is checking the RabbitMQ host."); var factory = new ConnectionFactory() { Uri = new Uri(_rabbitMqConnectionString) }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { _logger?.LogInformation($"The {nameof(RabbitMQLiveness)} check success."); return(Task.FromResult( LivenessResult.Healthy())); } } catch (Exception ex) { _logger?.LogWarning($"The {nameof(RabbitMQLiveness)} check fail with the exception {ex.ToString()}."); return(Task.FromResult( LivenessResult.UnHealthy(ex))); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(AzureServiceBusTopicLiveness)} is checking the Azure Topic."); var topicClient = new TopicClient(_connectionString, _topicName); var scheduledMessageId = await topicClient.ScheduleMessageAsync( new Message(Encoding.UTF8.GetBytes(TEST_MESSAGE)), new DateTimeOffset(DateTime.UtcNow).AddHours(2)); await topicClient.CancelScheduledMessageAsync(scheduledMessageId); _logger?.LogInformation($"The {nameof(AzureServiceBusTopicLiveness)} check success."); return(LivenessResult.Healthy()); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(AzureServiceBusTopicLiveness)} check fail for {_connectionString} with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default(CancellationToken)) { try { var response = await _httpClient.GetAsync("_cluster/health"); response.EnsureSuccessStatusCode(); var json = await response.Content.ReadAsStringAsync(); var results = JsonConvert.DeserializeObject <ClusterHealth>(json); switch (results.status) { case ClusterStatus.Green: return(LivenessResult.Healthy("Green")); case ClusterStatus.Yellow: return(LivenessResult.Healthy("Yellow (no replicas)")); case ClusterStatus.Red: return(LivenessResult.UnHealthy("Red")); default: return(LivenessResult.UnHealthy("Unknown status - " + results.status)); } } catch (Exception ex) { return(LivenessResult.UnHealthy(ex)); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { foreach (var item in _options.ConfiguredHosts) { using (var tcpClient = new TcpClient()) { await tcpClient.ConnectAsync(item.host, item.port); if (!tcpClient.Connected) { return($"Connection to host {item.host}:{item.port} failed", false); } } } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { using (var httpClient = new HttpClient() { BaseAddress = _idSvrUri }) { var response = await httpClient.GetAsync(IDSVR_DISCOVER_CONFIGURATION_SEGMENT); if (!response.IsSuccessStatusCode) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Discover endpoint is not responding with 200 OK, the current status is {response.StatusCode} and the content { (await response.Content.ReadAsStringAsync())}"; return(message, false); } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { using (var smtpConnection = new SmtpConnection(_options)) { if (await smtpConnection.ConnectAsync()) { if (_options.AccountOptions.login) { var(user, password) = _options.AccountOptions.account; if (!await smtpConnection.AuthenticateAsync(user, password)) { return($"Error login to smtp server{_options.Host}:{_options.Port} with configured credentials", false); } } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } else { return($"Could not connect to smtp server {_options.Host}:{_options.Port} - SSL : {_options.ConnectionType}", false); } } } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { using (var connection = new NpgsqlConnection(_npgsqlConnectionString)) { try { await connection.OpenAsync(cancellationToken); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT 1;"; await command.ExecuteScalarAsync(); } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { foreach (var item in _options.ConfigureHosts.Values) { var ipAddresses = Dns.GetHostAddresses(item.Host) .Select(h => h.ToString()); foreach (var ipAddress in ipAddresses) { if (!item.Resolutions.Contains(ipAddress)) { return(await Task.FromResult(($"Ip Address {ipAddress} was not resolved from host {item.Host}", false))); } } } return(await Task.FromResult((BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true))); } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(await Task.FromResult((message, false))); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { using (var connection = new SqliteConnection(_connectionString)) { _logger?.LogInformation($"{nameof(SqliteLiveness)} is checking the Sqlite using the query {_sql}."); await connection.OpenAsync(cancellationToken); using (var command = connection.CreateCommand()) { command.CommandText = _sql; await command.ExecuteScalarAsync(); } _logger?.LogInformation($"The {nameof(SqliteLiveness)} check success for {_connectionString}"); return(LivenessResult.Healthy()); } } catch (Exception ex) { _logger?.LogWarning($"The {nameof(SqliteLiveness)} check fail for {_connectionString} with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { _imapConnection = new ImapConnection(_options); if (await _imapConnection.ConnectAsync()) { if (_options.AccountOptions.login) { return(await ExecuteAuthenticatedUserActions()); } } else { return($"Connection to server {_options.Host} has failed - SSL Enabled : {_options.ConnectionType}", false); } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } finally { _imapConnection.Dispose(); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { var configuredHosts = _options.ConfiguredHosts.Values; foreach (var item in configuredHosts) { try { using (var ping = new Ping()) { var pingReply = await ping.SendPingAsync(item.Host, item.TimeOut); if (pingReply.Status != IPStatus.Success) { return($"Ping check for host {item.Host} is failed with status reply:{pingReply.Status}", false); } } } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); }
public Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { var configuredDrives = _options.ConfiguredDrives.Values; foreach (var item in configuredDrives) { var systemDriveInfo = GetSystemDriveInfo(item.DriveName); if (systemDriveInfo.Exists) { if (systemDriveInfo.ActualFreeMegabytes < item.MinimumFreeMegabytes) { return(Task.FromResult(($"Minimum configured megabytes for disk {item.DriveName} is {item.MinimumFreeMegabytes} but actual free space are {systemDriveInfo.ActualFreeMegabytes} megabytes", false))); } } else { return(Task.FromResult(($"Configured drive {item.DriveName} is not present on system", false))); } } return(Task.FromResult((BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true))); } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(Task.FromResult((message, false))); } }
public Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(RedisLiveness)} is checking the Redis status."); ConnectionMultiplexer connection; if (!_connections.TryGetValue(_redisConnectionString, out connection)) { connection = ConnectionMultiplexer.Connect(_redisConnectionString); if (!_connections.TryAdd(_redisConnectionString, connection)) { return(Task.FromResult( LivenessResult.UnHealthy("Redis connection can't be added into the dictionary."))); } } connection.GetDatabase() .Ping(); _logger?.LogInformation($"The {nameof(RedisLiveness)} check success."); return(Task.FromResult( LivenessResult.Healthy())); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(RedisLiveness)} check fail with the exception {ex.ToString()}."); return(Task.FromResult( LivenessResult.UnHealthy(ex))); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { SqliteConnection connection = null; try { using (connection = new SqliteConnection(_connectionString)) { await connection.OpenAsync(); var selectCmd = connection.CreateCommand(); selectCmd.CommandText = _healthQuery; using (var reader = selectCmd.ExecuteReader()) { await reader.ReadAsync(); } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { using (var connection = new MySqlConnection(_connectionString)) { await connection.OpenAsync(cancellationToken); if (await connection.PingAsync(cancellationToken)) { return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } else { return(string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name), false); } } } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } }
public async Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { try { foreach (var item in _options.Hosts.Values) { var ftpRequest = CreateFtpWebRequest(item.host, item.createFile, item.credentials); using (var ftpResponse = (FtpWebResponse)await ftpRequest.GetResponseAsync()) { if (ftpResponse.StatusCode != FtpStatusCode.PathnameCreated && ftpResponse.StatusCode != FtpStatusCode.ClosingData) { return($"Error connecting to ftp host {item.host} the exit code eas {ftpResponse.StatusCode}", false); } } } return(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true); } catch (Exception ex) { var message = !livenessContext.IsDevelopment ? string.Format(BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_ERROR_MESSAGE, livenessContext.Name) : $"Exception {ex.GetType().Name} with message ('{ex.Message}')"; return(message, false); } }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { _logger?.LogInformation($"{nameof(FtpLiveness)} is checking FTP connections."); foreach (var item in _options.Hosts.Values) { var ftpRequest = CreateFtpWebRequest(item.host, item.createFile, item.credentials); using (var ftpResponse = (FtpWebResponse)await ftpRequest.GetResponseAsync()) { if (ftpResponse.StatusCode != FtpStatusCode.PathnameCreated && ftpResponse.StatusCode != FtpStatusCode.ClosingData) { _logger?.LogWarning($"The {nameof(FtpLiveness)} check fail for ftp host {item.host} with exit code {ftpResponse.StatusCode}."); LivenessResult.UnHealthy($"Error connecting to ftp host {item.host} with exit code {ftpResponse.StatusCode}"); } } } _logger?.LogInformation($"The {nameof(FtpLiveness)} check success."); return(LivenessResult.Healthy()); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(FtpLiveness)} check fail with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public Task <(string, bool)> IsHealthy(HttpContext context, LivenessExecutionContext livenessContext, CancellationToken cancellationToken = default) { var currentValue = currentValueFunc(); if (currentValue.CompareTo(maximunValue) <= 0) { return(Task.FromResult((BeatPulseKeys.BEATPULSE_HEALTHCHECK_DEFAULT_OK_MESSAGE, true))); } return(Task.FromResult(($"Maximun={maximunValue}, Current={currentValue}", false))); }
public async Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { var defaultHttpMethod = _options.HttpMethod; var defaultCodes = _options.ExpectedHttpCodes; var idx = 0; try { _logger?.LogInformation($"{nameof(UriLiveness)} is checking configured uri's."); foreach (var item in _options.UrisOptions) { var method = item.HttpMethod ?? defaultHttpMethod; var expectedCodes = item.ExpectedHttpCodes ?? defaultCodes; if (cancellationToken.IsCancellationRequested) { return(LivenessResult.UnHealthy($"Liveness execution is cancelled.")); } using (var httpClient = new HttpClient()) { var requestMessage = new HttpRequestMessage(method, item.Uri); foreach (var header in item.Headers) { requestMessage.Headers.Add(header.Name, header.Value); } var response = await httpClient.SendAsync(requestMessage); if (!((int)response.StatusCode >= expectedCodes.Min && (int)response.StatusCode <= expectedCodes.Max)) { _logger?.LogWarning($"The {nameof(UriLiveness)} check fail for uri {item.Uri}."); return(LivenessResult.UnHealthy($"Discover endpoint #{idx} is not responding with code in {expectedCodes.Min}...{expectedCodes.Max} range, the current status is {response.StatusCode}.")); } ++idx; } } _logger?.LogDebug($"The {nameof(UriLiveness)} check success."); return(LivenessResult.Healthy()); } catch (Exception ex) { _logger?.LogWarning($"The {nameof(UriLiveness)} check fail with the exception {ex.ToString()}."); return(LivenessResult.UnHealthy(ex)); } }
public Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { try { throw _throwException(); } catch (Exception ex) { return(Task.FromResult( LivenessResult.UnHealthy(ex))); } }
public Task <LivenessResult> IsHealthy(LivenessExecutionContext context, CancellationToken cancellationToken = default) { var currentValue = currentValueFunc(); if (currentValue.CompareTo(maximunValue) <= 0) { return(Task.FromResult( LivenessResult.Healthy())); } return(Task.FromResult( LivenessResult.UnHealthy($"Maximun={maximunValue}, Current={currentValue}"))); }