using System.Text.Json; using IM.Admin.Services; using IM.InitCommon.Management; namespace IM.Admin.Api; public static class MonitoringEndpoints { public static void MapMonitoring(this WebApplication app) { var api = app.MapGroup("/api/admin").RequireAuthorization("operate"); api.MapGet("/health", async (HealthSampler sampler, InternalClient client, CancellationToken ct) => { var health = await sampler.Read(ct); JsonElement? connections = null; try { connections = await client.Send("connector", "/internal/management/connections", ct: ct); } catch { } return ManagementResult.Ok(new { services = health, connections, sampledAt = DateTime.UtcNow }); }); api.MapGet("/storage", async (HttpContext c, InternalClient client) => ManagementResult.Ok(await client.Send("file", "/internal/management/storage/summary" + c.Request.QueryString, ct: c.RequestAborted))); app.MapGet("/api/admin/groups/{id:guid}/members", async (Guid id, HttpContext c, InternalClient client) => ManagementResult.Ok(await client.Send("group", $"/internal/management/members/{id}" + c.Request.QueryString, ct: c.RequestAborted))).RequireAuthorization(); } }