feat: add database and LDAP health checks with JSON response formatting

Implement health checks for SQL Server, Oracle databases (JDE, CMS, GIW), and LDAP servers to enable comprehensive system monitoring via the /health endpoint.
This commit is contained in:
Joseph Doherty
2026-01-30 07:24:33 -05:00
parent ee044d03e0
commit 993126273a
7 changed files with 394 additions and 1 deletions
+28 -1
View File
@@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.OpenApi.Models;
@@ -117,9 +118,35 @@ public static class ApiDependencyInjection
// Health check endpoint - no authentication required
app.MapHealthChecks("/health", new HealthCheckOptions
{
AllowCachingResponses = false
AllowCachingResponses = false,
ResponseWriter = WriteHealthCheckResponse
}).AllowAnonymous();
return app;
}
/// <summary>
/// Writes detailed JSON response for health check results.
/// </summary>
private static async Task WriteHealthCheckResponse(HttpContext context, HealthReport report)
{
context.Response.ContentType = "application/json";
var result = new
{
status = report.Status.ToString(),
totalDuration = report.TotalDuration.TotalMilliseconds,
checks = report.Entries.Select(e => new
{
name = e.Key,
status = e.Value.Status.ToString(),
description = e.Value.Description,
duration = e.Value.Duration.TotalMilliseconds,
data = e.Value.Data,
exception = e.Value.Exception?.Message
})
};
await context.Response.WriteAsJsonAsync(result);
}
}