- Agent : LogBufferService (ring buffer borné, drop-oldest), AgentLoggingProvider
(capture ILogger non-bloquante), LogSanitizer (masque password/token/secret/bearer),
LogUploadService (batch POST /api/agents/{id}/logs, retry, drop si 400)
- Central : entité AgentLogEntry + migration AddAgentLogEntries (index AgentId+TimestampUtc),
SubmitAgentLogsCommand (batch <= 200, entrées invalides ignorées),
GetAgentLogsQuery (pagination, filtres niveau/période/recherche),
endpoints POST + GET /api/agents/{id}/logs
- UI : onglet Logs dans AgentDetail (filtres, pagination, auto-refresh toggle)
- Logs agent enrichis : heartbeat succès (Debug), résolution IP (Debug)
- Tests : LogBufferServiceTests (6), AgentDetailLogsTests (4), handlers AgentLogs (8)
This commit is contained in:
1 parent
ab705e72fa
commit
0136bf33ec
28 files changed
+3261
-3
No files matched your search
@@ -4,6 +4,8 @@ using Heimdall.Application.AgentDiscovery.Commands.SubmitAgentDiscovery;
|
||||
using Heimdall.Application.Agents.Queries.GetAgent;
|
||||
using Heimdall.Application.Agents.Queries.GetAgentsBySite;
|
||||
using Heimdall.Application.Agents.Queries.GetAllAgents;
|
||||
using Heimdall.Application.AgentLogs.Commands.SubmitAgentLogs;
|
||||
using Heimdall.Application.AgentLogs.Queries.GetAgentLogs;
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Domain.Enums;
|
||||
using Heimdall.Infrastructure.Security;
|
||||
@@ -117,6 +119,44 @@ public class AgentsController : ControllerBase
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
/// <summary>Submit a batch of log entries from an agent (API Key auth).</summary>
|
||||
[Authorize(AuthenticationSchemes = "ApiKey")]
|
||||
[HttpPost("{id:guid}/logs")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> SubmitLogs(
|
||||
Guid id, [FromBody] SubmitAgentLogsRequest request, CancellationToken ct)
|
||||
{
|
||||
var command = new SubmitAgentLogsCommand(id, request.Entries);
|
||||
var result = await _mediator.Send(command, ct);
|
||||
return result.IsSuccess
|
||||
? Ok()
|
||||
: StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
}
|
||||
|
||||
/// <summary>Get agent log entries (JWT auth).</summary>
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)]
|
||||
[HttpGet("{id:guid}/logs")]
|
||||
[ProducesResponseType(typeof(PagedResult<AgentLogEntryDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> GetLogs(
|
||||
Guid id,
|
||||
[FromQuery] int page = 1,
|
||||
[FromQuery] int pageSize = 50,
|
||||
[FromQuery] string? level = null,
|
||||
[FromQuery] DateTime? from = null,
|
||||
[FromQuery] DateTime? to = null,
|
||||
[FromQuery] string? search = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var result = await _mediator.Send(
|
||||
new GetAgentLogsQuery(id, page, pageSize, level, from, to, search), ct);
|
||||
if (!result.IsSuccess)
|
||||
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
/// <summary>List all agents across all sites.</summary>
|
||||
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.SiteRead)]
|
||||
[HttpGet]
|
||||
|
||||
Reference in new issue
Block a user