@extends('admin.layouts.admin') @section('content') @php /** * ========================= * Helpers UI * ========================= */ $statusLabel = function(string $status) { return match($status) { 'ok' => 'UP', 'degraded' => 'DÉGRADÉ', 'maintenance' => 'MAINTENANCE', 'down' => 'DOWN', default => strtoupper($status), }; }; $statusText = function(string $status) { return match($status) { 'ok' => 'Opérationnel', 'degraded' => 'Dégradé', 'maintenance' => 'Maintenance', 'down' => 'Incident', default => 'Inconnu', }; }; $statusPill = function(string $status) { return match($status) { 'ok' => 'bg-emerald-50 text-emerald-800 ring-1 ring-emerald-200', 'degraded' => 'bg-amber-50 text-amber-800 ring-1 ring-amber-200', 'maintenance' => 'bg-sky-50 text-sky-800 ring-1 ring-sky-200', 'down' => 'bg-rose-50 text-rose-800 ring-1 ring-rose-200', default => 'bg-slate-50 text-slate-700 ring-1 ring-slate-200', }; }; $dot = function(string $status) { return match($status) { 'ok' => 'bg-emerald-500', 'degraded' => 'bg-amber-400', 'maintenance' => 'bg-sky-500', 'down' => 'bg-rose-500', default => 'bg-slate-400', }; }; $kpiCard = function(string $tone) { return match($tone) { 'down' => 'border-rose-200 bg-rose-50/40', 'up' => 'border-emerald-200 bg-emerald-50/40', 'maintenance' => 'border-sky-200 bg-sky-50/40', 'degraded' => 'border-amber-200 bg-amber-50/40', default => 'border-slate-200 bg-white', }; }; $kpiDot = function(string $tone) { return match($tone) { 'down' => 'bg-rose-500', 'up' => 'bg-emerald-500', 'maintenance' => 'bg-sky-500', 'degraded' => 'bg-amber-400', default => 'bg-slate-400', }; }; /** * ========================= * Maintenance message logic (Option B like client) * ========================= */ $activeMessage = $activeMessage ?? null; $affectedMonitorIds = $affectedMonitorIds ?? []; $isMonitorAffected = function(int $monitorId) use ($activeMessage, $affectedMonitorIds) { if (empty($activeMessage) || empty($activeMessage->is_active)) return false; if (empty($affectedMonitorIds)) return true; // message global => toutes return in_array($monitorId, $affectedMonitorIds, true); }; // OPTION B: message maintenance actif + sonde ciblée => statut effectif = maintenance $effectiveStatus = function($m) use ($isMonitorAffected) { if ($isMonitorAffected((int)$m->id)) { return 'maintenance'; } return $m->forced_status ?: ($m->last_status ?: 'down'); }; /** * ========================= * KPIs basés sur le statut effectif * ========================= */ $all = collect($monitors ?? []); $kpiDown = $all->filter(fn($m) => $effectiveStatus($m) === 'down')->count(); $kpiDegraded = $all->filter(fn($m) => $effectiveStatus($m) === 'degraded')->count(); $kpiMaint = $all->filter(fn($m) => $effectiveStatus($m) === 'maintenance')->count(); $kpiUp = $all->filter(fn($m) => $effectiveStatus($m) === 'ok')->count(); // UP = ok uniquement (maintenance exclue + degraded séparé) // Tu peux garder ton ancien $kpis si tu veux, mais on force celui-ci pour être cohérent. $kpis = [ 'down' => $kpiDown, 'up' => $kpiUp, 'degraded' => $kpiDegraded, 'maintenance' => $kpiMaint, ]; $maintBox = function(?string $sev) { return match($sev) { 'yellow' => 'border-amber-200 bg-amber-50 text-amber-950', 'orange' => 'border-orange-200 bg-orange-50 text-orange-950', 'red' => 'border-rose-200 bg-rose-50 text-rose-950', default => 'border-slate-200 bg-slate-50 text-slate-900', }; }; $maintPill = function(?string $sev) { return match($sev) { 'yellow' => 'bg-amber-200 text-amber-950', 'orange' => 'bg-orange-200 text-orange-950', 'red' => 'bg-rose-200 text-rose-950', default => 'bg-slate-200 text-slate-900', }; }; @endphp
Vue globale du statut de tes sondes.
| Sonde | Catégorie | Type | Cible | État | Dernier check | Actions |
|---|---|---|---|---|---|---|
|
{{ $m->name }}
@if($affected)
Maintenance (message)
@endif
@if(!empty($m->forced_status))
Statut forcé
@endif
{{ $m->description }}
@endif
{{ $m->target }}
•
{{ $m->type }}
@if(count($meta))
•
{{ implode(' • ', $meta) }}
@endif
@if($m->last_error && $status === 'down')
{{ $m->last_error }}
@endif
|
{{ $m->category?->name ?? '-' }} | {{ strtoupper($m->type) }} | {{ $m->target }} | {{-- État --}}
{{ $statusLabel($status) }}
{{ $statusText($status) }}
|
{{-- Dernier check --}}
@if($m->last_checked_at)
{{ $m->last_checked_at->diffForHumans() }}
{{ $m->last_checked_at }}
@else
Jamais
@endif
|
{{-- Actions --}}
|
| Aucune sonde configurée. | ||||||