2026-07-17 19:08:17 +00:00
|
|
|
@page "/agents/{Id:guid}"
|
2026-07-19 07:25:27 +00:00
|
|
|
@attribute [Authorize(Policy = "Admin.Users")]
|
2026-07-17 19:08:17 +00:00
|
|
|
@layout MainLayout
|
|
|
|
|
@inject HeimdallApiClient Api
|
|
|
|
|
@inject ISnackbar Snackbar
|
|
|
|
|
@inject NavigationManager Nav
|
2026-07-18 19:07:01 +00:00
|
|
|
@implements IDisposable
|
2026-07-17 19:08:17 +00:00
|
|
|
|
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Dns" Class="mr-2" />
|
|
|
|
|
Agent : @_agent?.Name
|
|
|
|
|
</MudText>
|
|
|
|
|
|
|
|
|
|
@if (_loading)
|
|
|
|
|
{
|
2026-07-19 07:25:27 +00:00
|
|
|
<LoadingSkeleton LineCount="6" />
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
else if (_agent is null)
|
|
|
|
|
{
|
2026-07-19 07:25:27 +00:00
|
|
|
<EmptyState Icon="@Icons.Material.Filled.Dns"
|
|
|
|
|
Title="Agent introuvable"
|
|
|
|
|
Description="L'agent demandé n'existe pas ou a été supprimé.">
|
|
|
|
|
<ActionContent>
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Primary"
|
|
|
|
|
OnClick="@(() => Nav.NavigateTo("/admin/agents"))">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.ArrowBack" Class="mr-1" /> Retour aux agents
|
|
|
|
|
</MudButton>
|
|
|
|
|
</ActionContent>
|
|
|
|
|
</EmptyState>
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-07-19 07:25:27 +00:00
|
|
|
@* ─── Status Bar ─── *@
|
|
|
|
|
<div class="d-flex align-center mb-4">
|
|
|
|
|
<StatusChip Text="@_agent.Status"
|
|
|
|
|
Color="@GetStatusColor(_agent.Status)"
|
|
|
|
|
Icon="@GetStatusIcon(_agent.Status)"
|
|
|
|
|
Size="Size.Medium" />
|
|
|
|
|
<MudSpacer />
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">
|
|
|
|
|
Dernier heartbeat : @(_agent.LastHeartbeat?.ToString("g") ?? "Jamais")
|
|
|
|
|
</MudText>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-07-19 07:25:27 +00:00
|
|
|
<SectionCard Title="Informations" Icon="@Icons.Material.Filled.Info" Elevation="2">
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Hostname</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.Hostname</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Version</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.Version</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Statut</MudText>
|
|
|
|
|
<MudText Color="@GetStatusColor(_agent.Status)" Typo="Typo.body1">
|
|
|
|
|
@GetStatusIcon(_agent.Status) @_agent.Status
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">IP publique</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@(_agent.PublicIp ?? "-")</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Dernier heartbeat</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@(_agent.LastHeartbeat?.ToString("g") ?? "Jamais")</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Enregistré le</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.CreatedAt.ToString("g")</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
2026-07-19 07:25:27 +00:00
|
|
|
</SectionCard>
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12" md="6">
|
2026-07-19 07:25:27 +00:00
|
|
|
<SectionCard Title="Capacités" Icon="@Icons.Material.Filled.Dns" Elevation="2">
|
2026-07-17 19:08:17 +00:00
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">CPU</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@_agent.CpuCores cœurs</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">Mémoire</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">@FormatMemory(_agent.MemoryMb)</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="6" Class="mt-2">
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">GPU</MudText>
|
|
|
|
|
<MudText Typo="Typo.body1">
|
|
|
|
|
<MudIcon Icon="@(_agent.HasGpu ? Icons.Material.Filled.CheckCircle : Icons.Material.Filled.Cancel)"
|
|
|
|
|
Color="@(_agent.HasGpu ? Color.Success : Color.Default)" Size="Size.Small" />
|
|
|
|
|
@(_agent.HasGpu ? _agent.GpuType : "Aucun")
|
|
|
|
|
</MudText>
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
2026-07-19 07:25:27 +00:00
|
|
|
</SectionCard>
|
2026-07-17 19:08:17 +00:00
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
@* ─── Agent Settings Overrides ─── *@
|
2026-07-19 07:25:27 +00:00
|
|
|
<SectionCard Title="Configuration spécifique"
|
|
|
|
|
Icon="@Icons.Material.Filled.Tune"
|
|
|
|
|
Elevation="2"
|
|
|
|
|
HelpText="Ces réglages prennent le pas sur la configuration globale pour cet agent uniquement. Envoyés en temps réel via SignalR.">
|
2026-07-18 19:07:01 +00:00
|
|
|
|
|
|
|
|
@if (_settingsLoading)
|
|
|
|
|
{
|
|
|
|
|
<MudProgressCircular Indeterminate="true" Size="Size.Small" />
|
|
|
|
|
}
|
|
|
|
|
else if (_settingsError)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Error" Class="mb-4">
|
|
|
|
|
Erreur lors du chargement de la configuration
|
|
|
|
|
<MudButton OnClick="@LoadSettingsAsync" Size="Size.Small" Variant="Variant.Text" Class="ml-2">Réessayer</MudButton>
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else if (_settings.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
<MudAlert Severity="Severity.Info" Class="mb-4">
|
|
|
|
|
Aucune configuration spécifique pour cet agent.
|
|
|
|
|
Ajoutez un réglage pour surcharger la configuration globale.
|
|
|
|
|
</MudAlert>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<MudTable Items="@_settings" Hover="true" Dense="true" Class="mb-4">
|
|
|
|
|
<ColGroup>
|
|
|
|
|
<col style="width: 40%;" />
|
|
|
|
|
<col style="width: 40%;" />
|
|
|
|
|
<col style="width: 20%;" />
|
|
|
|
|
</ColGroup>
|
|
|
|
|
<HeaderContent>
|
|
|
|
|
<MudTh>Clé</MudTh>
|
|
|
|
|
<MudTh>Valeur</MudTh>
|
|
|
|
|
<MudTh>Actions</MudTh>
|
|
|
|
|
</HeaderContent>
|
|
|
|
|
<RowTemplate>
|
|
|
|
|
<MudTd><MudText Typo="Typo.body2">@context.Key</MudText></MudTd>
|
|
|
|
|
<MudTd><MudText Typo="Typo.body2">@context.Value</MudText></MudTd>
|
|
|
|
|
<MudTd>
|
2026-07-19 07:12:40 +00:00
|
|
|
<MudTooltip Text="Modifier ce réglage (envoyé en temps réel via SignalR)">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" Size="Size.Small"
|
|
|
|
|
OnClick="@(() => OpenEditDialog(context))" />
|
|
|
|
|
</MudTooltip>
|
|
|
|
|
<MudTooltip Text="Supprimer ce réglage">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
|
|
|
|
OnClick="@(() => ConfirmRemoveSetting(context))" />
|
|
|
|
|
</MudTooltip>
|
2026-07-18 19:07:01 +00:00
|
|
|
</MudTd>
|
|
|
|
|
</RowTemplate>
|
|
|
|
|
</MudTable>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
|
|
|
|
OnClick="@OpenAddDialog" Class="mt-2">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-1" />
|
|
|
|
|
Ajouter un réglage
|
|
|
|
|
</MudButton>
|
2026-07-19 07:25:27 +00:00
|
|
|
</SectionCard>
|
2026-07-18 19:07:01 +00:00
|
|
|
|
2026-07-19 07:25:27 +00:00
|
|
|
<div class="d-flex gap-4 mt-4">
|
|
|
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Default"
|
|
|
|
|
OnClick="@(() => Nav.NavigateTo($"/sites/{_agent.SiteId}/agents"))">
|
|
|
|
|
← Agents du site
|
|
|
|
|
</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Text" Color="Color.Default"
|
|
|
|
|
OnClick="@(() => Nav.NavigateTo("/admin/agents"))">
|
|
|
|
|
← Tous les agents
|
|
|
|
|
</MudButton>
|
|
|
|
|
</div>
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
@* ─── Delete Confirmation Dialog ─── *@
|
|
|
|
|
<MudDialog @bind-Visible="_confirmDeleteVisible" Options="_dialogOptions">
|
|
|
|
|
<TitleContent>
|
|
|
|
|
<MudText Typo="Typo.h6">
|
|
|
|
|
<MudIcon Icon="@Icons.Material.Filled.Warning" Color="Color.Warning" Class="mr-2" />
|
|
|
|
|
Confirmer la suppression
|
|
|
|
|
</MudText>
|
|
|
|
|
</TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<MudText>Supprimer le réglage <strong>@_deletingKey</strong> pour cet agent ?</MudText>
|
|
|
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="mt-2">
|
|
|
|
|
L'agent sera notifié en temps réel via SignalR et utilisera la valeur globale par défaut.
|
|
|
|
|
</MudText>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _confirmDeleteVisible = false)">Annuler</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Error"
|
|
|
|
|
OnClick="@ExecuteRemoveSettingAsync"
|
|
|
|
|
Loading="@_deleting"
|
|
|
|
|
Disabled="@_deleting">Supprimer</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
|
|
|
|
@* ─── Add / Edit Dialog ─── *@
|
|
|
|
|
<MudDialog @bind-Visible="_showEditDialog" Options="_dialogOptions">
|
|
|
|
|
<TitleContent>
|
|
|
|
|
<MudText Typo="Typo.h6">@(_editingSetting is null ? "Ajouter un réglage" : "Modifier le réglage")</MudText>
|
|
|
|
|
</TitleContent>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<MudGrid>
|
|
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudTextField Label="Clé"
|
|
|
|
|
@bind-Value="_editKey"
|
|
|
|
|
Disabled="@(_editingSetting is not null)"
|
|
|
|
|
For="@(() => _editKey)"
|
|
|
|
|
Required="true"
|
|
|
|
|
HelperText="Ex: heartbeat.interval.seconds" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
<MudItem xs="12">
|
|
|
|
|
<MudTextField Label="Valeur"
|
|
|
|
|
@bind-Value="_editValue"
|
|
|
|
|
For="@(() => _editValue)"
|
|
|
|
|
Required="true" />
|
|
|
|
|
</MudItem>
|
|
|
|
|
</MudGrid>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<MudButton Variant="Variant.Text" OnClick="@(() => _showEditDialog = false)">Annuler</MudButton>
|
|
|
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
|
|
|
|
OnClick="@SaveSettingAsync"
|
|
|
|
|
Disabled="@_saving"
|
|
|
|
|
Loading="@_saving">
|
|
|
|
|
@(_editingSetting is null ? "Ajouter" : "Enregistrer")
|
|
|
|
|
</MudButton>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</MudDialog>
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
@code {
|
|
|
|
|
[Parameter] public Guid Id { get; set; }
|
|
|
|
|
|
|
|
|
|
private AgentItem? _agent;
|
|
|
|
|
private bool _loading = true;
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
// Settings
|
|
|
|
|
private List<AgentSettingItem> _settings = [];
|
|
|
|
|
private bool _settingsLoading;
|
|
|
|
|
private bool _settingsError;
|
|
|
|
|
private bool _saving;
|
|
|
|
|
private AgentSettingItem? _editingSetting;
|
|
|
|
|
private string _editKey = string.Empty;
|
|
|
|
|
private string _editValue = string.Empty;
|
|
|
|
|
private bool _showEditDialog;
|
|
|
|
|
private bool _confirmDeleteVisible;
|
|
|
|
|
private string _deletingKey = string.Empty;
|
|
|
|
|
private bool _deleting;
|
|
|
|
|
private readonly DialogOptions _dialogOptions = new()
|
|
|
|
|
{
|
|
|
|
|
MaxWidth = MaxWidth.Small,
|
|
|
|
|
FullWidth = true,
|
|
|
|
|
CloseButton = true
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_agent = await Api.GetAgentAsync(Id);
|
2026-07-18 19:07:01 +00:00
|
|
|
if (_agent is not null)
|
|
|
|
|
await LoadSettingsAsync();
|
2026-07-17 19:08:17 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _loading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 19:07:01 +00:00
|
|
|
private async Task LoadSettingsAsync()
|
|
|
|
|
{
|
|
|
|
|
_settingsError = false;
|
|
|
|
|
_settingsLoading = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_settings = await Api.GetAgentSettingsAsync(Id);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_settingsError = true;
|
|
|
|
|
_settings = [];
|
|
|
|
|
}
|
|
|
|
|
finally { _settingsLoading = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenAddDialog()
|
|
|
|
|
{
|
|
|
|
|
_editingSetting = null;
|
|
|
|
|
_editKey = string.Empty;
|
|
|
|
|
_editValue = string.Empty;
|
|
|
|
|
_showEditDialog = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenEditDialog(AgentSettingItem setting)
|
|
|
|
|
{
|
|
|
|
|
_editingSetting = setting;
|
|
|
|
|
_editKey = setting.Key;
|
|
|
|
|
_editValue = setting.Value;
|
|
|
|
|
_showEditDialog = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveSettingAsync()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(_editKey)) return;
|
|
|
|
|
|
|
|
|
|
_saving = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var request = new SetAgentSettingRequest(_editKey.Trim(), _editValue);
|
|
|
|
|
var response = await Api.SetAgentSettingAsync(Id, request);
|
|
|
|
|
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add("Réglage enregistré et envoyé à l'agent en temps réel", Severity.Success);
|
|
|
|
|
_showEditDialog = false;
|
|
|
|
|
await LoadSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var error = await response.Content.ReadAsStringAsync();
|
|
|
|
|
Snackbar.Add($"Erreur : {error}", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _saving = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ConfirmRemoveSetting(AgentSettingItem setting)
|
|
|
|
|
{
|
|
|
|
|
_deletingKey = setting.Key;
|
|
|
|
|
_confirmDeleteVisible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task ExecuteRemoveSettingAsync()
|
|
|
|
|
{
|
|
|
|
|
_deleting = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = await Api.RemoveAgentSettingAsync(Id, _deletingKey);
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
_confirmDeleteVisible = false;
|
|
|
|
|
Snackbar.Add("Réglage supprimé, agent notifié en temps réel", Severity.Success);
|
|
|
|
|
await LoadSettingsAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Snackbar.Add("Erreur lors de la suppression", Severity.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
|
|
|
|
|
finally { _deleting = false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
// No unmanaged resources to dispose
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-17 19:08:17 +00:00
|
|
|
private static Color GetStatusColor(string status) => status switch
|
|
|
|
|
{
|
|
|
|
|
"Online" => Color.Success,
|
|
|
|
|
"Offline" => Color.Error,
|
|
|
|
|
"Error" => Color.Warning,
|
|
|
|
|
_ => Color.Default
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string GetStatusIcon(string status) => status switch
|
|
|
|
|
{
|
|
|
|
|
"Online" => "●",
|
|
|
|
|
"Offline" => "○",
|
|
|
|
|
"Error" => "⚠",
|
|
|
|
|
_ => "?"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string FormatMemory(long mb) => mb switch
|
|
|
|
|
{
|
|
|
|
|
> 102400 => $"{mb / 1024:F0} Go",
|
|
|
|
|
> 0 => $"{mb} Mo",
|
|
|
|
|
_ => "-"
|
|
|
|
|
};
|
|
|
|
|
}
|