diff --git a/src/Heimdall.Agent/Logging/AgentLoggingProvider.cs b/src/Heimdall.Agent/Logging/AgentLoggingProvider.cs
new file mode 100644
index 0000000..c20ac94
--- /dev/null
+++ b/src/Heimdall.Agent/Logging/AgentLoggingProvider.cs
@@ -0,0 +1,69 @@
+using Microsoft.Extensions.Logging;
+
+namespace Heimdall.Agent.Logging;
+
+///
+/// Additional that captures every log entry
+/// passing the process-wide filter (RuntimeLogLevel) into the
+/// for upload to the Central.
+/// This is a sink only: it never writes to console or files, so the
+/// existing stdout/Docker output is untouched.
+///
+public sealed class AgentLoggingProvider : ILoggerProvider
+{
+ private readonly LogBufferService _buffer;
+
+ public AgentLoggingProvider(LogBufferService buffer) => _buffer = buffer;
+
+ public ILogger CreateLogger(string categoryName) => new BufferLogger(_buffer, categoryName);
+
+ public void Dispose() { }
+
+ private sealed class BufferLogger : ILogger
+ {
+ private readonly LogBufferService _buffer;
+ private readonly string _category;
+
+ public BufferLogger(LogBufferService buffer, string category)
+ {
+ _buffer = buffer;
+ _category = category;
+ }
+
+ public IDisposable? BeginScope(TState state) where TState : notnull => null;
+
+ public bool IsEnabled(LogLevel logLevel) => true;
+
+ public void Log(
+ LogLevel logLevel,
+ EventId eventId,
+ TState state,
+ Exception? exception,
+ Func formatter)
+ {
+ try
+ {
+ var message = LogSanitizer.Sanitize(formatter(state, exception));
+ if (string.IsNullOrWhiteSpace(message))
+ return;
+
+ _buffer.Enqueue(new BufferedLogEntry(
+ DateTime.UtcNow,
+ logLevel,
+ message,
+ LogSanitizer.Sanitize(exception?.ToString()),
+ ShortCategory(_category)));
+ }
+ catch (Exception)
+ {
+ // Logging must never crash the caller (FFmpeg/YOLO hot path).
+ }
+ }
+
+ private static string ShortCategory(string category)
+ {
+ var dot = category.LastIndexOf('.');
+ return dot >= 0 ? category[(dot + 1)..] : category;
+ }
+ }
+}
diff --git a/src/Heimdall.Agent/Logging/LogBufferService.cs b/src/Heimdall.Agent/Logging/LogBufferService.cs
new file mode 100644
index 0000000..4f675dc
--- /dev/null
+++ b/src/Heimdall.Agent/Logging/LogBufferService.cs
@@ -0,0 +1,83 @@
+using System.Collections.Concurrent;
+using Microsoft.Extensions.Logging;
+
+namespace Heimdall.Agent.Logging;
+
+///
+/// Captured log entry waiting to be uploaded to the Central.
+///
+public readonly record struct BufferedLogEntry(
+ DateTime TimestampUtc,
+ LogLevel Level,
+ string Message,
+ string? Exception,
+ string? Source);
+
+///
+/// Bounded, thread-safe in-memory buffer of log entries produced by the
+/// agent and destined for the Central's POST /api/agents/{id}/logs.
+///
+///
+/// Full-buffer policy: drop oldest. The most recent entries are the
+/// most useful for diagnosing the agent's current state (a fresh Error must
+/// never be dropped because a burst of older Warnings filled the buffer).
+/// Dropped entries are counted so the operator can see the agent is logging
+/// faster than it uploads. Logging never blocks the caller.
+///
+public sealed class LogBufferService
+{
+ private readonly ConcurrentQueue _queue = new();
+ private readonly int _capacity;
+ private int _droppedCount;
+
+ public LogBufferService(int capacity = 500)
+ {
+ _capacity = capacity > 0 ? capacity : 500;
+ }
+
+ public int Capacity => _capacity;
+
+ /// Number of entries dropped because the buffer was full.
+ public int DroppedCount => Volatile.Read(ref _droppedCount);
+
+ /// Current number of buffered entries.
+ public int Count => _queue.Count;
+
+ ///
+ /// Adds an entry, dropping the oldest one when the buffer is full.
+ /// Never throws and never blocks the logging hot path.
+ ///
+ public void Enqueue(BufferedLogEntry entry)
+ {
+ _queue.Enqueue(entry);
+
+ while (_queue.Count > _capacity)
+ {
+ if (_queue.TryDequeue(out _))
+ Interlocked.Increment(ref _droppedCount);
+ else
+ break;
+ }
+ }
+
+ ///
+ /// Atomically removes and returns all buffered entries (oldest first).
+ ///
+ public IReadOnlyList TakeAll()
+ {
+ if (_queue.IsEmpty)
+ return [];
+
+ var entries = new List(_queue.Count);
+ while (_queue.TryDequeue(out var entry))
+ entries.Add(entry);
+ return entries;
+ }
+
+ /// Re-queues entries that failed to upload (drops oldest if needed).
+ public void Requeue(IEnumerable entries)
+ {
+ foreach (var entry in entries)
+ Enqueue(entry);
+ }
+}
diff --git a/src/Heimdall.Agent/Logging/LogSanitizer.cs b/src/Heimdall.Agent/Logging/LogSanitizer.cs
new file mode 100644
index 0000000..3c62ff0
--- /dev/null
+++ b/src/Heimdall.Agent/Logging/LogSanitizer.cs
@@ -0,0 +1,26 @@
+using System.Text.RegularExpressions;
+
+namespace Heimdall.Agent.Logging;
+
+///
+/// Masks secrets in log messages before they leave the agent (spec P1:
+/// "Secrets dans logs — sanitized : password, token, secret, snapshotUrl").
+/// Applied to both message and exception text at capture time.
+///
+public static partial class LogSanitizer
+{
+ // Matches "key=value", "key: value", "key= 'value'" or JSON "key":"value"
+ // for well-known secret keys. Also handles "Authorization: Bearer ".
+ [GeneratedRegex(
+ @"(?i)(?password|passwd|pwd|token|secret|apikey|api_key|authorization|snapshoturl|credential|private[_-]?key)(['""]?\s*[:=]\s*)(?['""]?)(?:(?:bearer|basic)\s+)?(?[^'""\s,;&]+)",
+ RegexOptions.Compiled)]
+ private static partial Regex SecretValueRegex();
+
+ public static string Sanitize(string? text)
+ {
+ if (string.IsNullOrEmpty(text))
+ return string.Empty;
+
+ return SecretValueRegex().Replace(text, "${key}${2}${3}***");
+ }
+}
diff --git a/src/Heimdall.Agent/Program.cs b/src/Heimdall.Agent/Program.cs
index 3a829e0..6361d7c 100644
--- a/src/Heimdall.Agent/Program.cs
+++ b/src/Heimdall.Agent/Program.cs
@@ -1,9 +1,11 @@
using Sentry.AspNetCore;
using Heimdall.Agent;
+using Heimdall.Agent.Logging;
using Heimdall.Agent.Services;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
+using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
var builder = WebApplication.CreateSlimBuilder(args);
@@ -69,6 +71,12 @@ builder.Services.AddHostedService();
builder.Services.AddHostedService();
builder.Services.AddHostedService();
+// Log capture & upload to Central (ticket #50)
+builder.Services.AddSingleton();
+builder.Services.AddSingleton();
+builder.Services.AddSingleton(sp => sp.GetRequiredService());
+builder.Services.AddHostedService();
+
// Health checks — used by Docker HEALTHCHECK
builder.Services.AddHealthChecks()
.AddCheck("agent_health", tags: ["ready"]);
diff --git a/src/Heimdall.Agent/Services/AgentRegistrationService.cs b/src/Heimdall.Agent/Services/AgentRegistrationService.cs
index f966e79..aca1d7e 100644
--- a/src/Heimdall.Agent/Services/AgentRegistrationService.cs
+++ b/src/Heimdall.Agent/Services/AgentRegistrationService.cs
@@ -15,6 +15,7 @@ public class AgentRegistrationService : BackgroundService
private readonly AgentState _state;
private readonly AgentOptions _options;
private readonly SystemMetricsProvider _metrics;
+ private readonly Logging.LogBufferService _buffer;
private HttpClient? _client;
public AgentRegistrationService(
@@ -22,12 +23,14 @@ public class AgentRegistrationService : BackgroundService
AgentState state,
IOptions options,
SystemMetricsProvider metrics,
+ Logging.LogBufferService buffer,
ILogger logger)
{
_httpClientFactory = httpClientFactory;
_state = state;
_options = options.Value;
_metrics = metrics;
+ _buffer = buffer;
_logger = logger;
}
@@ -165,6 +168,11 @@ public class AgentRegistrationService : BackgroundService
{
_logger.LogWarning("Heartbeat failed: {StatusCode}", heartbeatResponse.StatusCode);
}
+ else
+ {
+ _logger.LogDebug("Heartbeat OK — agent online, {Buffered} log(s) buffered",
+ _buffer.Count);
+ }
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
@@ -187,10 +195,13 @@ public class AgentRegistrationService : BackgroundService
var http = _httpClientFactory.CreateClient("IpResolver");
http.Timeout = TimeSpan.FromSeconds(5);
var ip = await http.GetStringAsync("https://api.ipify.org", ct);
- return ip?.Trim();
+ ip = ip?.Trim();
+ _logger.LogDebug("Public IP resolved: {Ip}", ip);
+ return ip;
}
- catch
+ catch (Exception ex)
{
+ _logger.LogDebug("Public IP resolution failed ({Error}); reporting null", ex.Message);
return null;
}
}
diff --git a/src/Heimdall.Agent/Services/LogUploadService.cs b/src/Heimdall.Agent/Services/LogUploadService.cs
new file mode 100644
index 0000000..b35d6a4
--- /dev/null
+++ b/src/Heimdall.Agent/Services/LogUploadService.cs
@@ -0,0 +1,117 @@
+using System.Net.Http.Json;
+using System.Text.Json.Serialization;
+using Heimdall.Agent.Logging;
+using Heimdall.Agent.Services;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+
+namespace Heimdall.Agent.Services;
+
+///
+/// Periodically flushes the agent's to the
+/// Central via POST /api/agents/{id}/logs (API Key auth).
+/// Non-blocking by design: if the Central is unreachable the entries are
+/// re-queued and retried on the next tick; a 400 (validation) drops the
+/// batch to avoid an infinite retry loop.
+///
+public class LogUploadService : BackgroundService
+{
+ private readonly IHttpClientFactory _httpClientFactory;
+ private readonly LogBufferService _buffer;
+ private readonly AgentState _state;
+ private readonly ILogger _logger;
+
+ public LogUploadService(
+ IHttpClientFactory httpClientFactory,
+ LogBufferService buffer,
+ AgentState state,
+ ILogger logger)
+ {
+ _httpClientFactory = httpClientFactory;
+ _buffer = buffer;
+ _state = state;
+ _logger = logger;
+ }
+
+ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
+ {
+ using var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
+
+ while (await timer.WaitForNextTickAsync(stoppingToken).ConfigureAwait(false))
+ {
+ try
+ {
+ await UploadOnceAsync(stoppingToken).ConfigureAwait(false);
+ }
+ catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
+ {
+ break;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogWarning(ex, "Log upload tick failed (non-fatal)");
+ }
+ }
+ }
+
+ internal async Task UploadOnceAsync(CancellationToken ct)
+ {
+ // No registered identity yet → nothing to attach logs to.
+ if (_state.AgentId == Guid.Empty || string.IsNullOrEmpty(_state.ApiKey))
+ return;
+
+ var entries = _buffer.TakeAll();
+ if (entries.Count == 0)
+ return;
+
+ var client = _httpClientFactory.CreateClient("Central");
+ client.DefaultRequestHeaders.Remove("X-API-Key");
+ client.DefaultRequestHeaders.Add("X-API-Key", _state.ApiKey);
+
+ var payload = new
+ {
+ entries = entries.Select(e => new
+ {
+ timestampUtc = e.TimestampUtc,
+ level = e.Level.ToString(),
+ message = e.Message,
+ exception = e.Exception,
+ source = e.Source
+ }).ToList()
+ };
+
+ try
+ {
+ using var response = await client.PostAsJsonAsync(
+ $"api/agents/{_state.AgentId}/logs", payload, ct).ConfigureAwait(false);
+
+ if (response.IsSuccessStatusCode)
+ {
+ if (_buffer.DroppedCount > 0)
+ _logger.LogWarning(
+ "Log upload OK; {Count} entries uploaded, {Dropped} dropped (buffer full)",
+ entries.Count, _buffer.DroppedCount);
+ return;
+ }
+
+ if ((int)response.StatusCode == 400)
+ {
+ // Validation error — re-sending the same batch will never succeed.
+ _logger.LogWarning(
+ "Central rejected log batch ({Status}): dropping {Count} entries",
+ (int)response.StatusCode, entries.Count);
+ return;
+ }
+
+ _logger.LogWarning(
+ "Log upload failed ({Status}); {Count} entries re-queued",
+ (int)response.StatusCode, entries.Count);
+ _buffer.Requeue(entries);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogDebug("Log upload failed (network): {Error}; {Count} entries re-queued", ex.Message, entries.Count);
+ _buffer.Requeue(entries);
+ }
+ }
+}
diff --git a/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsCommand.cs b/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsCommand.cs
new file mode 100644
index 0000000..decdcff
--- /dev/null
+++ b/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsCommand.cs
@@ -0,0 +1,9 @@
+using Heimdall.Application.Common;
+using Heimdall.Application.DTOs;
+using MediatR;
+
+namespace Heimdall.Application.AgentLogs.Commands.SubmitAgentLogs;
+
+public record SubmitAgentLogsCommand(
+ Guid AgentId,
+ IReadOnlyList Entries) : IRequest;
diff --git a/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsHandler.cs b/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsHandler.cs
new file mode 100644
index 0000000..2cc25a2
--- /dev/null
+++ b/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsHandler.cs
@@ -0,0 +1,68 @@
+using Heimdall.Application.Common;
+using Heimdall.Application.DTOs;
+using Heimdall.Domain.Entities;
+using Heimdall.Domain.Enums;
+using MediatR;
+using Microsoft.EntityFrameworkCore;
+
+namespace Heimdall.Application.AgentLogs.Commands.SubmitAgentLogs;
+
+public class SubmitAgentLogsHandler : IRequestHandler
+{
+ private readonly IApplicationDbContext _db;
+
+ public SubmitAgentLogsHandler(IApplicationDbContext db) => _db = db;
+
+ public async Task Handle(SubmitAgentLogsCommand request, CancellationToken ct)
+ {
+ var agentExists = await _db.Agents
+ .AnyAsync(a => a.Id == request.AgentId, ct)
+ .ConfigureAwait(false);
+ if (!agentExists)
+ return ServiceResult.NotFound("Agent not found");
+
+ var nowUtc = DateTime.UtcNow;
+ var entries = new List(request.Entries.Count);
+
+ foreach (var entry in request.Entries)
+ {
+ // Skip malformed entries instead of failing the whole batch:
+ // an agent misconfiguration must not block log collection.
+ if (!Enum.TryParse(entry.Level, true, out var level))
+ continue;
+ if (string.IsNullOrWhiteSpace(entry.Message))
+ continue;
+
+ var timestamp = entry.TimestampUtc.Kind == DateTimeKind.Unspecified
+ ? DateTime.SpecifyKind(entry.TimestampUtc, DateTimeKind.Utc)
+ : entry.TimestampUtc.ToUniversalTime();
+
+ // Clamp absurdly old timestamps (agent buffered through a long outage);
+ // entries in the future are dropped by the validator.
+ if (timestamp < nowUtc.AddDays(-30))
+ continue;
+
+ entries.Add(new AgentLogEntry(
+ request.AgentId,
+ timestamp,
+ level,
+ entry.Message.Trim(),
+ Normalize(entry.Exception),
+ Normalize(entry.Source)));
+ }
+
+ if (entries.Count == 0)
+ return ServiceResult.Failure("No valid log entries in batch", 400);
+
+ foreach (var entry in entries)
+ _db.AgentLogEntries.Add(entry);
+ await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false);
+ return ServiceResult.Success();
+ }
+
+ private static string? Normalize(string? value)
+ {
+ var trimmed = value?.Trim();
+ return string.IsNullOrWhiteSpace(trimmed) ? null : trimmed;
+ }
+}
diff --git a/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsValidator.cs b/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsValidator.cs
new file mode 100644
index 0000000..56efd4f
--- /dev/null
+++ b/src/Heimdall.Application/AgentLogs/Commands/SubmitAgentLogs/SubmitAgentLogsValidator.cs
@@ -0,0 +1,39 @@
+using Heimdall.Application.AgentLogs.Commands.SubmitAgentLogs;
+using FluentValidation;
+
+namespace Heimdall.Application.AgentLogs.Commands.SubmitAgentLogs;
+
+public class SubmitAgentLogsValidator : AbstractValidator
+{
+ public const int MaxBatchSize = 200;
+ public const int MaxMessageLength = 2000;
+
+ public SubmitAgentLogsValidator()
+ {
+ RuleFor(x => x.AgentId)
+ .NotEmpty();
+
+ RuleFor(x => x.Entries)
+ .NotNull()
+ .NotEmpty()
+ .WithMessage("Log entries are required.")
+ .Must(e => e.Count <= MaxBatchSize)
+ .WithMessage($"Batch size exceeds the maximum of {MaxBatchSize} entries.");
+
+ RuleForEach(x => x.Entries)
+ .ChildRules(entry =>
+ {
+ entry.RuleFor(e => e.Message)
+ .NotEmpty()
+ .WithMessage("Log message is required.")
+ .MaximumLength(MaxMessageLength)
+ .WithMessage($"Log message exceeds {MaxMessageLength} characters.");
+
+ entry.RuleFor(e => e.TimestampUtc)
+ .Must(ts => ts.Kind == DateTimeKind.Utc || ts.Kind == DateTimeKind.Unspecified)
+ .WithMessage("TimestampUtc must be UTC.")
+ .Must(ts => ts <= DateTime.UtcNow.AddMinutes(5))
+ .WithMessage("TimestampUtc is in the future (clock skew > 5 min).");
+ });
+ }
+}
diff --git a/src/Heimdall.Application/AgentLogs/Queries/GetAgentLogs/GetAgentLogsHandler.cs b/src/Heimdall.Application/AgentLogs/Queries/GetAgentLogs/GetAgentLogsHandler.cs
new file mode 100644
index 0000000..0f3339f
--- /dev/null
+++ b/src/Heimdall.Application/AgentLogs/Queries/GetAgentLogs/GetAgentLogsHandler.cs
@@ -0,0 +1,60 @@
+using Heimdall.Application.AgentLogs.Queries.GetAgentLogs;
+using Heimdall.Application.Common;
+using Heimdall.Application.DTOs;
+using Heimdall.Domain.Enums;
+using MediatR;
+using Microsoft.EntityFrameworkCore;
+
+namespace Heimdall.Application.AgentLogs.Queries.GetAgentLogs;
+
+public class GetAgentLogsHandler : IRequestHandler>>
+{
+ private readonly IApplicationDbContext _db;
+
+ public GetAgentLogsHandler(IApplicationDbContext db) => _db = db;
+
+ public async Task>> Handle(GetAgentLogsQuery request, CancellationToken ct)
+ {
+ var query = _db.AgentLogEntries.Where(e => e.AgentId == request.AgentId);
+
+ if (!string.IsNullOrWhiteSpace(request.Level)
+ && Enum.TryParse(request.Level, true, out var level))
+ {
+ query = query.Where(e => e.Level == level);
+ }
+
+ if (request.From.HasValue)
+ query = query.Where(e => e.TimestampUtc >= request.From.Value.ToUniversalTime());
+
+ if (request.To.HasValue)
+ query = query.Where(e => e.TimestampUtc <= request.To.Value.ToUniversalTime());
+
+ if (!string.IsNullOrWhiteSpace(request.Search))
+ {
+ var search = request.Search.Trim();
+ query = query.Where(e =>
+ e.Message.Contains(search, StringComparison.OrdinalIgnoreCase)
+ || (e.Source != null && e.Source.Contains(search, StringComparison.OrdinalIgnoreCase)));
+ }
+
+ var total = await query.CountAsync(ct).ConfigureAwait(false);
+
+ var items = await query
+ .OrderByDescending(e => e.TimestampUtc)
+ .Skip((request.Page - 1) * request.PageSize)
+ .Take(request.PageSize)
+ .Select(e => new AgentLogEntryDto(
+ e.Id,
+ e.AgentId,
+ e.TimestampUtc,
+ e.Level.ToString(),
+ e.Message,
+ e.Exception,
+ e.Source))
+ .ToListAsync(ct)
+ .ConfigureAwait(false);
+
+ return ServiceResult>.Success(
+ new PagedResult(items, total, request.Page, request.PageSize));
+ }
+}
diff --git a/src/Heimdall.Application/AgentLogs/Queries/GetAgentLogs/GetAgentLogsQuery.cs b/src/Heimdall.Application/AgentLogs/Queries/GetAgentLogs/GetAgentLogsQuery.cs
new file mode 100644
index 0000000..078bf83
--- /dev/null
+++ b/src/Heimdall.Application/AgentLogs/Queries/GetAgentLogs/GetAgentLogsQuery.cs
@@ -0,0 +1,14 @@
+using Heimdall.Application.Common;
+using Heimdall.Application.DTOs;
+using MediatR;
+
+namespace Heimdall.Application.AgentLogs.Queries.GetAgentLogs;
+
+public record GetAgentLogsQuery(
+ Guid AgentId,
+ int Page = 1,
+ int PageSize = 50,
+ string? Level = null,
+ DateTime? From = null,
+ DateTime? To = null,
+ string? Search = null) : IRequest>>;
diff --git a/src/Heimdall.Application/Common/IApplicationDbContext.cs b/src/Heimdall.Application/Common/IApplicationDbContext.cs
index 27ab50f..02b9d7d 100644
--- a/src/Heimdall.Application/Common/IApplicationDbContext.cs
+++ b/src/Heimdall.Application/Common/IApplicationDbContext.cs
@@ -6,6 +6,7 @@ namespace Heimdall.Application.Common;
public interface IApplicationDbContext
{
DbSet Agents { get; }
+ DbSet AgentLogEntries { get; }
DbSet AgentSettings { get; }
DbSet ApiKeys { get; }
DbSet AppSettings { get; }
diff --git a/src/Heimdall.Application/DTOs/AgentLogDto.cs b/src/Heimdall.Application/DTOs/AgentLogDto.cs
new file mode 100644
index 0000000..f2902b4
--- /dev/null
+++ b/src/Heimdall.Application/DTOs/AgentLogDto.cs
@@ -0,0 +1,23 @@
+namespace Heimdall.Application.DTOs;
+
+/// Single log entry as submitted by an agent.
+public record AgentLogEntryRequest(
+ DateTime TimestampUtc,
+ string Level,
+ string Message,
+ string? Exception = null,
+ string? Source = null);
+
+/// Batch of log entries submitted by an agent.
+public record SubmitAgentLogsRequest(
+ IReadOnlyList Entries);
+
+/// Log entry as returned to the admin UI.
+public record AgentLogEntryDto(
+ Guid Id,
+ Guid AgentId,
+ DateTime TimestampUtc,
+ string Level,
+ string Message,
+ string? Exception,
+ string? Source);
diff --git a/src/Heimdall.Domain/Entities/AgentLogEntry.cs b/src/Heimdall.Domain/Entities/AgentLogEntry.cs
new file mode 100644
index 0000000..3e4171b
--- /dev/null
+++ b/src/Heimdall.Domain/Entities/AgentLogEntry.cs
@@ -0,0 +1,39 @@
+using Heimdall.Domain.Enums;
+
+namespace Heimdall.Domain.Entities;
+
+///
+/// Append-only log entry reported by an agent (FFmpeg, YOLO, RTSP, lifecycle…).
+/// Purged periodically by the AgentLogCleanupJob (retention policy).
+///
+public class AgentLogEntry
+{
+ public Guid Id { get; private set; } = Guid.NewGuid();
+ public Guid AgentId { get; private set; }
+ public DateTime TimestampUtc { get; private set; }
+ public AgentLogLevel Level { get; private set; }
+ public string Message { get; private set; } = string.Empty;
+ public string? Exception { get; private set; }
+ public string? Source { get; private set; }
+
+ // Navigation
+ public Agent Agent { get; private set; } = null!;
+
+ private AgentLogEntry() { } // EF Core
+
+ public AgentLogEntry(
+ Guid agentId,
+ DateTime timestampUtc,
+ AgentLogLevel level,
+ string message,
+ string? exception = null,
+ string? source = null)
+ {
+ AgentId = agentId;
+ TimestampUtc = timestampUtc;
+ Level = level;
+ Message = message;
+ Exception = exception;
+ Source = source;
+ }
+}
diff --git a/src/Heimdall.Domain/Enums/AgentLogLevel.cs b/src/Heimdall.Domain/Enums/AgentLogLevel.cs
new file mode 100644
index 0000000..35e5af8
--- /dev/null
+++ b/src/Heimdall.Domain/Enums/AgentLogLevel.cs
@@ -0,0 +1,14 @@
+namespace Heimdall.Domain.Enums;
+
+///
+/// Severity level of an agent log entry, mirroring Microsoft.Extensions.Logging levels.
+///
+public enum AgentLogLevel
+{
+ Trace = 0,
+ Debug = 1,
+ Information = 2,
+ Warning = 3,
+ Error = 4,
+ Critical = 5
+}
diff --git a/src/Heimdall.Infrastructure/Data/AppDbContext.cs b/src/Heimdall.Infrastructure/Data/AppDbContext.cs
index 7ec75e4..9386679 100644
--- a/src/Heimdall.Infrastructure/Data/AppDbContext.cs
+++ b/src/Heimdall.Infrastructure/Data/AppDbContext.cs
@@ -23,6 +23,7 @@ public class AppDbContext : IdentityDbContext, IApplicat
public DbSet Sites => Set();
public DbSet SiteCredentials => Set();
public DbSet Agents => Set();
+ public DbSet AgentLogEntries => Set();
public DbSet Cameras => Set();
public DbSet CameraCredentials => Set();
public DbSet CameraDetectionProfiles => Set();
diff --git a/src/Heimdall.Infrastructure/Data/Configurations/AgentLogEntryConfiguration.cs b/src/Heimdall.Infrastructure/Data/Configurations/AgentLogEntryConfiguration.cs
new file mode 100644
index 0000000..1e24d4c
--- /dev/null
+++ b/src/Heimdall.Infrastructure/Data/Configurations/AgentLogEntryConfiguration.cs
@@ -0,0 +1,44 @@
+using Heimdall.Domain.Entities;
+using Heimdall.Domain.Enums;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+namespace Heimdall.Infrastructure.Data.Configurations;
+
+public class AgentLogEntryConfiguration : IEntityTypeConfiguration
+{
+ public void Configure(EntityTypeBuilder builder)
+ {
+ builder.ToTable("agent_log_entries");
+
+ builder.HasKey(e => e.Id);
+
+ builder.Property(e => e.TimestampUtc)
+ .IsRequired();
+
+ builder.Property(e => e.Level)
+ .HasConversion()
+ .HasMaxLength(20)
+ .IsRequired()
+ .IsUnicode(false);
+
+ builder.Property(e => e.Message)
+ .HasMaxLength(2000)
+ .IsRequired();
+
+ builder.Property(e => e.Exception)
+ .HasMaxLength(4000);
+
+ builder.Property(e => e.Source)
+ .HasMaxLength(200)
+ .IsUnicode(false);
+
+ // Composite index: reads per agent (logs page) + purge by age.
+ builder.HasIndex(e => new { e.AgentId, e.TimestampUtc });
+
+ builder.HasOne(e => e.Agent)
+ .WithMany()
+ .HasForeignKey(e => e.AgentId)
+ .OnDelete(DeleteBehavior.Cascade);
+ }
+}
diff --git a/src/Heimdall.Infrastructure/Migrations/20260811163117_AddAgentLogEntries.Designer.cs b/src/Heimdall.Infrastructure/Migrations/20260811163117_AddAgentLogEntries.Designer.cs
new file mode 100644
index 0000000..26ab59e
--- /dev/null
+++ b/src/Heimdall.Infrastructure/Migrations/20260811163117_AddAgentLogEntries.Designer.cs
@@ -0,0 +1,1881 @@
+//
+using System;
+using Heimdall.Infrastructure.Data;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace Heimdall.Infrastructure.Migrations
+{
+ [DbContext(typeof(AppDbContext))]
+ [Migration("20260811163117_AddAgentLogEntries")]
+ partial class AddAgentLogEntries
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "10.0.8")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.Agent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("ApiKeyHash")
+ .HasMaxLength(128)
+ .IsUnicode(false)
+ .HasColumnType("character varying(128)");
+
+ b.Property("ApiKeyPrefix")
+ .HasMaxLength(8)
+ .IsUnicode(false)
+ .HasColumnType("character varying(8)");
+
+ b.Property("CpuCores")
+ .HasColumnType("integer");
+
+ b.Property("CpuUsagePercent")
+ .HasColumnType("double precision");
+
+ b.Property("CreatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DiskUsagePercent")
+ .HasColumnType("double precision");
+
+ b.Property("GpuType")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("HasGpu")
+ .HasColumnType("boolean");
+
+ b.Property("Hostname")
+ .IsRequired()
+ .HasMaxLength(255)
+ .IsUnicode(false)
+ .HasColumnType("character varying(255)");
+
+ b.Property("IsDeleted")
+ .HasColumnType("boolean");
+
+ b.Property("LastHeartbeat")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("MemoryMb")
+ .HasColumnType("bigint");
+
+ b.Property("MemoryUsageBytes")
+ .HasColumnType("bigint");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("PublicIp")
+ .HasMaxLength(45)
+ .IsUnicode(false)
+ .HasColumnType("character varying(45)");
+
+ b.Property("SiteId")
+ .HasColumnType("uuid");
+
+ b.Property("Status")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("UpdatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("UptimeSeconds")
+ .HasColumnType("bigint");
+
+ b.Property("Version")
+ .IsRequired()
+ .HasMaxLength(50)
+ .IsUnicode(false)
+ .HasColumnType("character varying(50)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("LastHeartbeat")
+ .HasFilter("\"Status\" = 'Online'");
+
+ b.HasIndex("SiteId");
+
+ b.ToTable("agents", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.AgentLogEntry", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AgentId")
+ .HasColumnType("uuid");
+
+ b.Property("Exception")
+ .HasMaxLength(4000)
+ .HasColumnType("character varying(4000)");
+
+ b.Property("Level")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("Message")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property("Source")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("TimestampUtc")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AgentId", "TimestampUtc");
+
+ b.ToTable("agent_log_entries", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.AgentSetting", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AgentId")
+ .HasColumnType("uuid")
+ .HasColumnName("agent_id");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone")
+ .HasColumnName("created_at");
+
+ b.Property("Key")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("character varying(200)")
+ .HasColumnName("key");
+
+ b.Property("UpdatedAt")
+ .HasColumnType("timestamp with time zone")
+ .HasColumnName("updated_at");
+
+ b.Property("Value")
+ .IsRequired()
+ .HasColumnType("text")
+ .HasColumnName("value");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AgentId", "Key")
+ .IsUnique();
+
+ b.ToTable("agent_settings", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.ApiKey", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("CreatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("CreatedByUserId")
+ .HasColumnType("uuid");
+
+ b.Property("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property("ExpiresAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("KeyHash")
+ .IsRequired()
+ .HasMaxLength(128)
+ .IsUnicode(false)
+ .HasColumnType("character varying(128)");
+
+ b.Property("KeyPrefix")
+ .IsRequired()
+ .HasMaxLength(8)
+ .IsUnicode(false)
+ .HasColumnType("character varying(8)");
+
+ b.Property("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("SiteId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("KeyHash");
+
+ b.HasIndex("KeyPrefix");
+
+ b.HasIndex("SiteId");
+
+ b.ToTable("api_keys", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.AppRole", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken()
+ .HasColumnType("text");
+
+ b.Property("Name")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property("NormalizedName")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedName")
+ .IsUnique()
+ .HasDatabaseName("RoleNameIndex");
+
+ b.ToTable("roles", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.AppSetting", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AgentScoped")
+ .HasColumnType("boolean");
+
+ b.Property("AllowedValues")
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)")
+ .HasColumnName("allowed_values");
+
+ b.Property("Category")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)")
+ .HasColumnName("category");
+
+ b.Property("CreatedAt")
+ .HasColumnType("timestamp with time zone")
+ .HasColumnName("created_at");
+
+ b.Property("Description")
+ .HasMaxLength(500)
+ .HasColumnType("character varying(500)")
+ .HasColumnName("description");
+
+ b.Property("Key")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("character varying(200)")
+ .HasColumnName("key");
+
+ b.Property("UpdatedAt")
+ .HasColumnType("timestamp with time zone")
+ .HasColumnName("updated_at");
+
+ b.Property("Value")
+ .IsRequired()
+ .HasColumnType("text")
+ .HasColumnName("value");
+
+ b.Property("ValueType")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)")
+ .HasColumnName("value_type");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Key")
+ .IsUnique();
+
+ b.ToTable("app_settings", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.AppUser", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AccessFailedCount")
+ .HasColumnType("integer");
+
+ b.Property("ConcurrencyStamp")
+ .IsConcurrencyToken()
+ .HasColumnType("text");
+
+ b.Property("CreatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("DisplayName")
+ .IsRequired()
+ .HasMaxLength(200)
+ .HasColumnType("character varying(200)");
+
+ b.Property("Email")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property("EmailConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property("Language")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(10)
+ .IsUnicode(false)
+ .HasColumnType("character varying(10)")
+ .HasDefaultValue("fr");
+
+ b.Property("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("MustChangePassword")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("boolean")
+ .HasDefaultValue(false);
+
+ b.Property("NormalizedEmail")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property("NormalizedUserName")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property("PasswordHash")
+ .HasColumnType("text");
+
+ b.Property("PhoneNumber")
+ .HasColumnType("text");
+
+ b.Property("PhoneNumberConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property("Theme")
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)")
+ .HasDefaultValue("Auto");
+
+ b.Property("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property("UserName")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedEmail")
+ .HasDatabaseName("EmailIndex");
+
+ b.HasIndex("NormalizedUserName")
+ .IsUnique()
+ .HasDatabaseName("UserNameIndex");
+
+ b.ToTable("users", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.AuditLog", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("Action")
+ .IsRequired()
+ .HasMaxLength(100)
+ .IsUnicode(false)
+ .HasColumnType("character varying(100)");
+
+ b.Property("IpAddress")
+ .HasMaxLength(45)
+ .IsUnicode(false)
+ .HasColumnType("character varying(45)");
+
+ b.Property("NewValue")
+ .HasColumnType("text");
+
+ b.Property("OldValue")
+ .HasColumnType("text");
+
+ b.Property("ResourceId")
+ .HasMaxLength(100)
+ .IsUnicode(false)
+ .HasColumnType("character varying(100)");
+
+ b.Property("ResourceType")
+ .IsRequired()
+ .HasMaxLength(100)
+ .IsUnicode(false)
+ .HasColumnType("character varying(100)");
+
+ b.Property("Timestamp")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("UserId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Timestamp")
+ .IsDescending();
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("ResourceType", "ResourceId", "Timestamp")
+ .IsDescending(false, false, true);
+
+ b.ToTable("audit_logs", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.Camera", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AgentId")
+ .HasColumnType("uuid");
+
+ b.Property("Capabilities")
+ .IsRequired()
+ .HasMaxLength(64)
+ .IsUnicode(false)
+ .HasColumnType("character varying(64)");
+
+ b.Property("CreatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("DeletedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DetectedType")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("DiscoveryMethod")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("HasAudio")
+ .HasColumnType("boolean");
+
+ b.Property("HasMotionDetection")
+ .HasColumnType("boolean");
+
+ b.Property("HasPtz")
+ .HasColumnType("boolean");
+
+ b.Property("HttpPort")
+ .HasColumnType("integer");
+
+ b.Property("IpAddress")
+ .HasMaxLength(45)
+ .HasColumnType("character varying(45)");
+
+ b.Property("IsDeleted")
+ .HasColumnType("boolean");
+
+ b.Property("LastDiscoveredAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("LastStreamTestAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("LastTestedCodecs")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("LastTestedHeight")
+ .HasColumnType("integer");
+
+ b.Property("LastTestedLatencyMs")
+ .HasColumnType("bigint");
+
+ b.Property("LastTestedWidth")
+ .HasColumnType("integer");
+
+ b.Property("MacAddress")
+ .HasMaxLength(17)
+ .HasColumnType("character varying(17)");
+
+ b.Property("Manufacturer")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property("Model")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("OnvifPort")
+ .HasColumnType("integer");
+
+ b.Property("RtspPort")
+ .HasColumnType("integer");
+
+ b.Property("RtspUrl")
+ .HasMaxLength(1000)
+ .IsUnicode(false)
+ .HasColumnType("character varying(1000)");
+
+ b.Property("SiteId")
+ .HasColumnType("uuid");
+
+ b.Property("Status")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("SubRtspUrl")
+ .HasMaxLength(1000)
+ .IsUnicode(false)
+ .HasColumnType("character varying(1000)");
+
+ b.Property("UpdatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AgentId");
+
+ b.HasIndex("IpAddress");
+
+ b.HasIndex("MacAddress");
+
+ b.HasIndex("SiteId");
+
+ b.ToTable("cameras", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.CameraAssignment", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AgentId")
+ .HasColumnType("uuid");
+
+ b.Property("AssignedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("CameraId")
+ .HasColumnType("uuid");
+
+ b.Property("Reason")
+ .IsRequired()
+ .HasMaxLength(50)
+ .IsUnicode(false)
+ .HasColumnType("character varying(50)");
+
+ b.Property("ReleasedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("AssignedAt");
+
+ b.HasIndex("AgentId", "ReleasedAt")
+ .HasFilter("\"ReleasedAt\" IS NULL");
+
+ b.HasIndex("CameraId", "ReleasedAt")
+ .IsUnique()
+ .HasFilter("\"ReleasedAt\" IS NULL");
+
+ b.ToTable("camera_assignments", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.CameraCredentials", b =>
+ {
+ b.Property("CameraId")
+ .HasColumnType("uuid");
+
+ b.Property("CreatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("OnvifPassword")
+ .IsRequired()
+ .HasMaxLength(500)
+ .IsUnicode(false)
+ .HasColumnType("character varying(500)");
+
+ b.Property("OnvifUsername")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(100)
+ .IsUnicode(false)
+ .HasColumnType("character varying(100)")
+ .HasDefaultValue("admin");
+
+ b.Property("RtspPassword")
+ .IsRequired()
+ .HasMaxLength(500)
+ .IsUnicode(false)
+ .HasColumnType("character varying(500)");
+
+ b.Property("RtspUsername")
+ .IsRequired()
+ .HasMaxLength(100)
+ .IsUnicode(false)
+ .HasColumnType("character varying(100)");
+
+ b.Property("UpdatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.HasKey("CameraId");
+
+ b.ToTable("camera_credentials", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.CameraDetectionProfile", b =>
+ {
+ b.Property("CameraId")
+ .HasColumnType("uuid");
+
+ b.Property("ActiveIntervalMs")
+ .HasColumnType("integer");
+
+ b.Property("AnimalCooldownSec")
+ .HasColumnType("integer");
+
+ b.Property("DetectAnimal")
+ .HasColumnType("boolean");
+
+ b.Property("DetectMotion")
+ .HasColumnType("boolean");
+
+ b.Property("DetectPackage")
+ .HasColumnType("boolean");
+
+ b.Property("DetectPerson")
+ .HasColumnType("boolean");
+
+ b.Property("DetectVehicle")
+ .HasColumnType("boolean");
+
+ b.Property("FaceRecognition")
+ .HasColumnType("boolean");
+
+ b.Property("IdleIntervalMs")
+ .HasColumnType("integer");
+
+ b.Property("IoUThreshold")
+ .HasColumnType("double precision");
+
+ b.Property("LicensePlateRecognition")
+ .HasColumnType("boolean");
+
+ b.Property("MaxEventsPerMinute")
+ .HasColumnType("integer");
+
+ b.Property("MinConfidence")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("double precision")
+ .HasDefaultValue(0.40000000000000002);
+
+ b.Property("MotionIntervalMs")
+ .HasColumnType("integer");
+
+ b.Property("MotionThreshold")
+ .HasColumnType("double precision");
+
+ b.Property("PersonCooldownSec")
+ .HasColumnType("integer");
+
+ b.Property("RequireMotionForAI")
+ .HasColumnType("boolean");
+
+ b.Property("VehicleCooldownSec")
+ .HasColumnType("integer");
+
+ b.Property("YoloModel")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasMaxLength(50)
+ .IsUnicode(false)
+ .HasColumnType("character varying(50)")
+ .HasDefaultValue("yolov8n");
+
+ b.HasKey("CameraId");
+
+ b.ToTable("camera_detection_profiles", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.CameraDiscoveryResult", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("DetectedType")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("DiscoveryMethod")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property("HomeKitDeviceId")
+ .HasMaxLength(50)
+ .IsUnicode(false)
+ .HasColumnType("character varying(50)");
+
+ b.Property("HomeKitModel")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("HomeKitName")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("Hostname")
+ .HasMaxLength(255)
+ .IsUnicode(false)
+ .HasColumnType("character varying(255)");
+
+ b.Property("HttpPort")
+ .HasColumnType("integer");
+
+ b.Property("HttpServerHeader")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("HttpStatusCode")
+ .HasColumnType("integer");
+
+ b.Property("IpAddress")
+ .IsRequired()
+ .HasMaxLength(45)
+ .IsUnicode(false)
+ .HasColumnType("character varying(45)");
+
+ b.Property("IsHomeKitCamera")
+ .HasColumnType("boolean");
+
+ b.Property("IsProcessed")
+ .HasColumnType("boolean");
+
+ b.Property("IsReachable")
+ .HasColumnType("boolean");
+
+ b.Property("MacAddress")
+ .HasMaxLength(17)
+ .IsUnicode(false)
+ .HasColumnType("character varying(17)");
+
+ b.Property("OnvifDeviceServiceUrl")
+ .HasMaxLength(500)
+ .IsUnicode(false)
+ .HasColumnType("character varying(500)");
+
+ b.Property("OnvifHardware")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("OnvifName")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("OnvifPort")
+ .HasColumnType("integer");
+
+ b.PrimitiveCollection("OpenPorts")
+ .IsRequired()
+ .IsUnicode(false)
+ .HasColumnType("integer[]");
+
+ b.Property("ProbedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("SiteId")
+ .HasColumnType("uuid");
+
+ b.Property("Vendor")
+ .HasMaxLength(100)
+ .IsUnicode(false)
+ .HasColumnType("character varying(100)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("IpAddress");
+
+ b.HasIndex("IsProcessed");
+
+ b.HasIndex("SiteId");
+
+ b.ToTable("camera_discovery_results", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.CameraEvent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property("AgentId")
+ .HasColumnType("uuid");
+
+ b.Property("CameraId")
+ .HasColumnType("uuid");
+
+ b.Property("Confidence")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("double precision")
+ .HasDefaultValue(0.0);
+
+ b.Property("CreatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.Property("Label")
+ .HasMaxLength(200)
+ .IsUnicode(false)
+ .HasColumnType("character varying(200)");
+
+ b.Property("MetadataJson")
+ .HasColumnType("jsonb");
+
+ b.Property("OccurredAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("SnapshotThumbUrl")
+ .HasMaxLength(2000)
+ .IsUnicode(false)
+ .HasColumnType("character varying(2000)");
+
+ b.Property("SnapshotUrl")
+ .HasMaxLength(2000)
+ .IsUnicode(false)
+ .HasColumnType("character varying(2000)");
+
+ b.Property("Type")
+ .HasColumnType("integer");
+
+ b.Property("UpdatedAt")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("timestamp with time zone")
+ .HasDefaultValueSql("NOW()");
+
+ b.HasKey("Id");
+
+ b.HasIndex("OccurredAt");
+
+ b.HasIndex("CameraId", "OccurredAt")
+ .IsDescending(false, true);
+
+ b.HasIndex("CameraId", "Type");
+
+ b.ToTable("camera_events", (string)null);
+ });
+
+ modelBuilder.Entity("Heimdall.Domain.Entities.DiscoveredStreamUrl", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.PrimitiveCollection("Codecs")
+ .IsRequired()
+ .IsUnicode(false)
+ .HasColumnType("text[]");
+
+ b.Property("DiscoveryResultId")
+ .HasColumnType("uuid");
+
+ b.Property("Height")
+ .HasColumnType("integer");
+
+ b.Property("IsAlive")
+ .HasColumnType("boolean");
+
+ b.Property("IsMainStream")
+ .HasColumnType("boolean");
+
+ b.Property("LatencyMs")
+ .HasColumnType("bigint");
+
+ b.Property("Protocol")
+ .IsRequired()
+ .HasMaxLength(20)
+ .IsUnicode(false)
+ .HasColumnType("character varying(20)");
+
+ b.Property