- AgentResponse expose CpuUsagePercent/MemoryUsageBytes/DiskUsagePercent/ UptimeSeconds (mappés dans les 3 handlers GetAgent/GetAll/GetBySite) - AgentItem client complété ; nouvelles tuiles AgentMetrics + MetricTile (jauges colorées) intégrées en ChildRowContent dans AllAgentsPage
178 lines
6.4 KiB
Plaintext
178 lines
6.4 KiB
Plaintext
@page "/admin/agents"
|
|
@attribute [Authorize(Policy = "Admin.Users")]
|
|
@layout MainLayout
|
|
@inject HeimdallApiClient Api
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudText Typo="Typo.h4" Class="mb-6">
|
|
<i class="fas fa-microchip mr-2"></i>
|
|
Agents
|
|
</MudText>
|
|
|
|
@if (_loading)
|
|
{
|
|
<LoadingSkeleton LineCount="6" />
|
|
}
|
|
else if (_error)
|
|
{
|
|
<MudAlert Severity="Severity.Error" Class="mb-4" Variant="Variant.Filled">
|
|
<MudText>Erreur lors du chargement des agents.</MudText>
|
|
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="@LoadData" Class="mt-2">
|
|
<MudIcon Icon="@Icons.Material.Filled.Refresh" Class="mr-1" Size="Size.Small" /> Réessayer
|
|
</MudButton>
|
|
</MudAlert>
|
|
}
|
|
else
|
|
{
|
|
@* ─── KPI Cards ─── *@
|
|
<MudGrid Class="mb-4">
|
|
@foreach (var stat in _agentStats)
|
|
{
|
|
<MudItem xs="12" sm="6" md="3" @key="stat.Label">
|
|
<MudPaper Elevation="1" Class="pa-3 d-flex align-center" Style="border-radius: 8px;">
|
|
<MudText Typo="Typo.h5" Class="mr-3 font-weight-bold" Style="@($"color:{stat.Color}")">@stat.Value</MudText>
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary">@stat.Label</MudText>
|
|
</MudPaper>
|
|
</MudItem>
|
|
}
|
|
</MudGrid>
|
|
|
|
@* ─── Filter Bar ─── *@
|
|
<FilterBar SearchPlaceholder="Rechercher un agent par nom, hostname ou IP..."
|
|
OnSearch="@(async () => { _page = 1; await LoadData(); })"
|
|
SearchChanged="@(async (s) => { _search = s; _page = 1; await LoadData(); })"
|
|
Reset="@(async () => { _search = ""; _page = 1; await LoadData(); })" />
|
|
|
|
@if (_agents is null || _agents.Count == 0)
|
|
{
|
|
<EmptyState Icon="@Icons.Material.Filled.Memory"
|
|
Title="Aucun agent déployé"
|
|
Description="Aucun agent n'est actuellement enregistré sur aucun site. Créez un site et générez un token d'enregistrement pour connecter un agent.">
|
|
<ActionContent>
|
|
<MudButton Variant="Variant.Outlined" Color="Color.Primary"
|
|
OnClick="@(() => Nav.NavigateTo("/sites"))">
|
|
<MudIcon Icon="@Icons.Material.Filled.Business" Class="mr-1" /> Voir les sites
|
|
</MudButton>
|
|
</ActionContent>
|
|
</EmptyState>
|
|
}
|
|
else
|
|
{
|
|
<MudTable Items="@_agents" Hover="true" Striped="true" Elevation="2">
|
|
<HeaderContent>
|
|
<MudTh>Nom</MudTh>
|
|
<MudTh>Site</MudTh>
|
|
<MudTh>Hostname</MudTh>
|
|
<MudTh>Version</MudTh>
|
|
<MudTh>Statut</MudTh>
|
|
<MudTh>Dernier heartbeat</MudTh>
|
|
<MudTh>IP</MudTh>
|
|
<MudTh>Actions</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Nom">
|
|
<MudLink Href="@($"/agents/{context.Id}")">@context.Name</MudLink>
|
|
</MudTd>
|
|
<MudTd DataLabel="Site">
|
|
<MudLink Href="@($"/sites/{context.SiteId}")">@context.SiteName</MudLink>
|
|
</MudTd>
|
|
<MudTd DataLabel="Hostname">@context.Hostname</MudTd>
|
|
<MudTd DataLabel="Version">@context.Version</MudTd>
|
|
<MudTd DataLabel="Statut">
|
|
<StatusChip Text="@context.Status"
|
|
Color="@GetStatusColor(context.Status)"
|
|
Icon="@GetStatusIcon(context.Status)" />
|
|
</MudTd>
|
|
<MudTd DataLabel="Dernier heartbeat">
|
|
@(context.LastHeartbeat?.ToString("g") ?? "Jamais")
|
|
</MudTd>
|
|
<MudTd DataLabel="IP">@context.PublicIp</MudTd>
|
|
<MudTd DataLabel="Actions">
|
|
<MudTooltip Text="Voir le détail de l'agent">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Visibility" Size="Size.Small"
|
|
OnClick="@(() => Nav.NavigateTo($"/agents/{context.Id}"))" />
|
|
</MudTooltip>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
<ChildRowContent>
|
|
<MudTd ColSpan="8">
|
|
<AgentMetrics Agent="@context" />
|
|
</MudTd>
|
|
</ChildRowContent>
|
|
</MudTable>
|
|
|
|
@* ─── Pagination ─── *@
|
|
<PaginationBar Page="@_page"
|
|
TotalPages="@_totalPages"
|
|
Total="@_total"
|
|
Previous="@(async () => await GoToPage(_page - 1))"
|
|
Next="@(async () => await GoToPage(_page + 1))" />
|
|
}
|
|
}
|
|
|
|
@code {
|
|
private IReadOnlyList<AgentItem>? _agents;
|
|
private List<AgentStatItem> _agentStats = [];
|
|
private bool _loading = true;
|
|
private bool _error;
|
|
private int _page = 1;
|
|
private int _totalPages = 1;
|
|
private int _total;
|
|
private string _search = "";
|
|
|
|
[Inject] private NavigationManager Nav { get; set; } = null!;
|
|
|
|
protected override async Task OnInitializedAsync() => await LoadData();
|
|
|
|
private async Task LoadData()
|
|
{
|
|
_loading = true;
|
|
_error = false;
|
|
try
|
|
{
|
|
var agentsTask = Api.GetAllAgentsAsync(_page);
|
|
var statsTask = Api.GetAgentStatsAsync();
|
|
|
|
await Task.WhenAll(agentsTask, statsTask);
|
|
|
|
var result = await agentsTask;
|
|
if (result is not null)
|
|
{
|
|
_agents = result.Items;
|
|
_total = result.TotalCount;
|
|
_totalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize));
|
|
}
|
|
|
|
_agentStats = await statsTask;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_error = true;
|
|
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
|
|
}
|
|
finally { _loading = false; }
|
|
}
|
|
|
|
private async Task GoToPage(int p)
|
|
{
|
|
_page = p;
|
|
await LoadData();
|
|
}
|
|
|
|
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" => Icons.Material.Filled.CheckCircle,
|
|
"Offline" => Icons.Material.Filled.Cancel,
|
|
"Error" => Icons.Material.Filled.Warning,
|
|
_ => Icons.Material.Filled.Help
|
|
};
|
|
}
|