126 lines
5.3 KiB
Plaintext
126 lines
5.3 KiB
Plaintext
@namespace Heimdall.Web.Components.Settings
|
|||
|
|
@inject HeimdallApiClient Api
|
||
|
|
@inject ISnackbar Snackbar
|
||
|
|
|
||
|
|
<MudPaper Elevation="1" Class="pa-4 mb-4" Style="border-radius: var(--hmd-radius-lg);">
|
||
|
|
<div class="d-flex align-center mb-3">
|
||
|
|
<MudText Typo="Typo.h6" Class="flex-grow-1">
|
||
|
|
<i class="fas fa-microchip mr-2"></i> Défauts agents
|
||
|
|
</MudText>
|
||
|
|
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary">Globaux</MudChip>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mb-3">
|
||
|
|
Valeurs par défaut appliquées à tous les agents. Chaque agent peut les surcharger individuellement.
|
||
|
|
</MudText>
|
||
|
|
|
||
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2">
|
||
|
|
<i class="fas fa-list mr-1" style="color: var(--mud-palette-primary);"></i> Logs
|
||
|
|
</MudText>
|
||
|
|
<MudGrid>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudSelect T="string" Label="Niveau de log global" Variant="Variant.Outlined"
|
||
|
|
Value="@(GetValue("log.level") ?? "info")"
|
||
|
|
ValueChanged="OnLogLevelChanged" Immediate="true"
|
||
|
|
HelperText="Appliqué à chaud aux agents (règle de niveau partagée).">
|
||
|
|
<MudSelectItem Value="@("trace")">Trace</MudSelectItem>
|
||
|
|
<MudSelectItem Value="@("debug")">Debug</MudSelectItem>
|
||
|
|
<MudSelectItem Value="@("info")">Info</MudSelectItem>
|
||
|
|
<MudSelectItem Value="@("warn")">Warn</MudSelectItem>
|
||
|
|
<MudSelectItem Value="@("error")">Error</MudSelectItem>
|
||
|
|
</MudSelect>
|
||
|
|
</MudItem>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudTextField T="string" Label="Rétention des logs agents (jours)" Variant="Variant.Outlined"
|
||
|
|
Type="InputType.Number"
|
||
|
|
Value="@GetValue("log.retentionDays")"
|
||
|
|
ValueChanged="OnRetentionChanged"
|
||
|
|
HelperText="Durée de conservation des logs remontés par les agents." />
|
||
|
|
</MudItem>
|
||
|
|
</MudGrid>
|
||
|
|
|
||
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
|
||
|
|
<i class="fas fa-heartbeat mr-1" style="color: var(--mud-palette-primary);"></i> Heartbeat
|
||
|
|
</MudText>
|
||
|
|
<MudGrid>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudTextField T="string" Label="Intervalle de heartbeat (secondes)" Variant="Variant.Outlined"
|
||
|
|
Type="InputType.Number"
|
||
|
|
Value="@GetValue("heartbeat.interval.seconds")"
|
||
|
|
ValueChanged="OnHeartbeatChanged"
|
||
|
|
HelperText="Fréquence de la remontée d'état des agents vers le central." />
|
||
|
|
</MudItem>
|
||
|
|
</MudGrid>
|
||
|
|
|
||
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2 mt-3">
|
||
|
|
<i class="fas fa-bug mr-1" style="color: var(--mud-palette-primary);"></i> Diagnostic
|
||
|
|
</MudText>
|
||
|
|
<MudGrid>
|
||
|
|
<MudItem xs="12" md="6">
|
||
|
|
<MudTextField T="string" Label="DSN Sentry / GlitchTip" Variant="Variant.Outlined"
|
||
|
|
Type="InputType.Password"
|
||
|
|
Value="@SecretValue("sentry.dsn")"
|
||
|
|
ValueChanged="OnSentryDsnChanged"
|
||
|
|
Placeholder="•••••••• (déjà configuré)"
|
||
|
|
HelperText="Endpoint de remontée d'erreurs. Nécessite un redémarrage pour être pris en compte." />
|
||
|
|
</MudItem>
|
||
|
|
</MudGrid>
|
||
|
|
</MudPaper>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
private List<AppSettingItem> _settings = [];
|
||
|
|
|
||
|
|
protected override async Task OnInitializedAsync()
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
_settings = await Api.GetSettingsAsync();
|
||
|
|
}
|
||
|
|
catch
|
||
|
|
{
|
||
|
|
_settings = [];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private string? GetValue(string key)
|
||
|
|
=> _settings.FirstOrDefault(s => s.Key == key)?.Value;
|
||
|
|
|
||
|
|
private string SecretValue(string key)
|
||
|
|
{
|
||
|
|
var v = GetValue(key);
|
||
|
|
return v is null or "" or "***REDACTED***" ? string.Empty : v;
|
||
|
|
}
|
||
|
|
|
||
|
|
private Task OnLogLevelChanged(string v) => SaveValueAsync("log.level", v);
|
||
|
|
private Task OnRetentionChanged(string v) => SaveValueAsync("log.retentionDays", v);
|
||
|
|
private Task OnHeartbeatChanged(string v) => SaveValueAsync("heartbeat.interval.seconds", v);
|
||
|
|
private Task OnSentryDsnChanged(string v) => SaveValueAsync("sentry.dsn", v);
|
||
|
|
|
||
|
|
private async Task SaveValueAsync(string key, string? value)
|
||
|
|
{
|
||
|
|
value ??= string.Empty;
|
||
|
|
var existing = _settings.FirstOrDefault(s => s.Key == key);
|
||
|
|
try
|
||
|
|
{
|
||
|
|
if (existing is null)
|
||
|
|
{
|
||
|
|
await Api.CreateSettingAsync(new CreateAppSettingRequest(
|
||
|
|
Key: key, Value: value,
|
||
|
|
Category: "agent",
|
||
|
|
Description: key, ValueType: "string", AllowedValues: null, AgentScoped: true));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
await Api.UpdateSettingAsync(key, new UpdateAppSettingRequest(
|
||
|
|
Value: value, Description: existing.Description ?? key,
|
||
|
|
Category: "agent", ValueType: "string", AllowedValues: null, AgentScoped: null));
|
||
|
|
}
|
||
|
|
_settings = await Api.GetSettingsAsync();
|
||
|
|
Snackbar.Add($"Paramètre {key} mis à jour", Severity.Success);
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
Snackbar.Add($"Échec de la mise à jour : {ex.Message}", Severity.Error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|