mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
[SG-497] BEEEP - Health Checks API Project (#2237)
* health check services added * health check extension added * added get connection string * made changes to hrslth check method * Added database health check * added identity server health check * added identity server health check * Added logger publisher * latest changes * removed file * Added mail server check for dev * Added authorization to health check url path * commented * Added exception to switch * Removed exclude code coverage * Added health check for redis * Added todos * Added storage queue checks * Added checks for mail * Removed unused references and fixed linting issue * Lint issues * Moved healthchecks to sharedWeb project and exposed builder as a parameter to configure more health checks based on a project * Added health check to API project * dependencies updated * Removed ef core health check dependencies * Added checks to only add a health check when the connection string exists, moved health check from startup to extension class * Merged with master and fixed conflicts * Fixed lint issues * Added check for amazon ses * merged with master * fixed lint * Removed Amazon SES health check
This commit is contained in:
60
src/SharedWeb/Health/HealthCheckServiceExtensions.cs
Normal file
60
src/SharedWeb/Health/HealthCheckServiceExtensions.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Bit.Core.Settings;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
|
||||
namespace Bit.SharedWeb.Health;
|
||||
|
||||
public static class HealthCheckServiceExtensions
|
||||
{
|
||||
public static void AddHealthCheckServices(this IServiceCollection services, GlobalSettings globalSettings,
|
||||
Action<IHealthChecksBuilder> addBuilder = null)
|
||||
{
|
||||
var builder = services.AddHealthChecks();
|
||||
addBuilder?.Invoke(builder);
|
||||
}
|
||||
|
||||
public static Task WriteResponse(HttpContext context, HealthReport healthReport)
|
||||
{
|
||||
context.Response.ContentType = "application/json; charset=utf-8";
|
||||
|
||||
var options = new JsonWriterOptions { Indented = true };
|
||||
|
||||
using var memoryStream = new MemoryStream();
|
||||
using (var jsonWriter = new Utf8JsonWriter(memoryStream, options))
|
||||
{
|
||||
jsonWriter.WriteStartObject();
|
||||
jsonWriter.WriteString("status", healthReport.Status.ToString());
|
||||
jsonWriter.WriteStartObject("results");
|
||||
|
||||
foreach (var healthReportEntry in healthReport.Entries)
|
||||
{
|
||||
jsonWriter.WriteStartObject(healthReportEntry.Key);
|
||||
jsonWriter.WriteString("status",
|
||||
healthReportEntry.Value.Status.ToString());
|
||||
jsonWriter.WriteString("description",
|
||||
healthReportEntry.Value.Description ?? healthReportEntry.Value.Exception?.Message);
|
||||
jsonWriter.WriteStartObject("data");
|
||||
|
||||
foreach (var item in healthReportEntry.Value.Data)
|
||||
{
|
||||
jsonWriter.WritePropertyName(item.Key);
|
||||
|
||||
JsonSerializer.Serialize(jsonWriter, item.Value,
|
||||
item.Value?.GetType() ?? typeof(object));
|
||||
}
|
||||
|
||||
jsonWriter.WriteEndObject();
|
||||
jsonWriter.WriteEndObject();
|
||||
}
|
||||
|
||||
jsonWriter.WriteEndObject();
|
||||
jsonWriter.WriteEndObject();
|
||||
}
|
||||
|
||||
return context.Response.WriteAsync(
|
||||
Encoding.UTF8.GetString(memoryStream.ToArray()));
|
||||
}
|
||||
}
|
@ -2786,7 +2786,7 @@
|
||||
"infrastructure.dapper": {
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"Core": "2023.3.0",
|
||||
"Core": "2023.4.3",
|
||||
"Dapper": "2.0.123"
|
||||
}
|
||||
},
|
||||
@ -2794,7 +2794,7 @@
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"AutoMapper.Extensions.Microsoft.DependencyInjection": "12.0.1",
|
||||
"Core": "2023.3.0",
|
||||
"Core": "2023.4.3",
|
||||
"Microsoft.EntityFrameworkCore.Relational": "6.0.12",
|
||||
"Microsoft.EntityFrameworkCore.SqlServer": "6.0.12",
|
||||
"Microsoft.EntityFrameworkCore.Sqlite": "6.0.12",
|
||||
|
Reference in New Issue
Block a user