@extends('layouts.app') @section('content')
{{-- 標題列 --}}

主機監控通知

@if($stats['unread'] > 0) {{ $stats['unread'] }} 未讀 @endif
{{-- 批次操作工具列(選取後顯示) --}}
@csrf @method('PATCH')
@csrf @method('DELETE')
@if(session('success'))
{{ session('success') }}
@endif {{-- 統計卡片 --}}
@foreach([ ['label'=>'全部', 'val'=>$stats['total'], 'icon'=>'bi-bell', 'bg'=>'#f1f5f9','color'=>'#64748b','q'=>[]], ['label'=>'已讀', 'val'=>$stats['read'], 'icon'=>'bi-check2-circle', 'bg'=>'#f0fdf4','color'=>'#16a34a','q'=>['read'=>'1']], ['label'=>'未讀', 'val'=>$stats['unread'], 'icon'=>'bi-bell-fill', 'bg'=>'#fee2e2','color'=>'#ef4444','q'=>['read'=>'0']], ['label'=>'嚴重', 'val'=>$stats['critical'], 'icon'=>'bi-x-octagon-fill', 'bg'=>'#fee2e2','color'=>'#dc2626','q'=>['level'=>'critical']], ['label'=>'錯誤', 'val'=>$stats['error'], 'icon'=>'bi-exclamation-octagon-fill', 'bg'=>'#ffedd5','color'=>'#ea580c','q'=>['level'=>'error']], ['label'=>'警告', 'val'=>$stats['warn'], 'icon'=>'bi-exclamation-triangle-fill','bg'=>'#fef3c7','color'=>'#d97706','q'=>['level'=>'warn']], ['label'=>'資訊', 'val'=>$stats['info'], 'icon'=>'bi-info-circle-fill', 'bg'=>'#eff6ff','color'=>'#3b82f6','q'=>['level'=>'info']], ] as $s) @endforeach
{{-- 類別快捷鈕 --}}
全部類別 @foreach($categories as $key => $cat) {{ $cat['label'] }} @endforeach
{{-- 篩選列 --}}
清除
{{-- 告警列表 --}}
@php $sortUrl = fn($f) => route('host-alerts.index', array_merge(request()->except(['sort','dir','page']), [ 'sort' => $f, 'dir' => ($sortField === $f && $sortDir === 'asc') ? 'desc' : 'asc', ])); $sortIcon = fn($f) => $sortField === $f ? ($sortDir === 'asc' ? '' : '') : ''; @endphp @forelse($alerts as $alert) @php $host = $alert->host; $proj = $host?->project; $client = $proj?->client; $isRead = $alert->isRead(); $isCrit = $alert->level === 'critical'; $levelBadge = match($alert->level) { 'critical' => ['bg'=>'bg-danger', 'icon'=>'bi-x-octagon', 'label'=>'嚴重'], 'error' => ['bg'=>'', 'icon'=>'bi-exclamation-octagon', 'label'=>'錯誤', 'style'=>'background:#ea580c;color:#fff'], 'warn' => ['bg'=>'bg-warning text-dark', 'icon'=>'bi-exclamation-triangle','label'=>'警告'], default => ['bg'=>'bg-info text-dark', 'icon'=>'bi-info-circle', 'label'=>'資訊'], }; $caseNo = 'ALR-' . $alert->created_at->format('Y') . '-' . str_pad($alert->id, 5, '0', STR_PAD_LEFT); $normalizedAlerts = collect($alert->alerts ?? [])->map(fn($item) => is_string($item) ? ['category'=>'system','level'=>'warn','message'=>$item,'suggestion'=>null] : $item ); $byCategory = $normalizedAlerts->groupBy('category'); $modalData = json_encode([ 'id' => $alert->id, 'case_no' => $caseNo, 'level' => $alert->level, 'time' => $alert->created_at->format('Y-m-d H:i:s'), 'time_rel' => $alert->created_at->diffForHumans(), 'client' => $client?->name ?? '', 'host' => $host?->name ?? '已刪除', 'ip' => $host?->ip_address ?? '', 'host_url' => $host ? route('hosts.show', $host) : '', 'email_sent' => $alert->email_sent, 'read' => $isRead, 'alerts' => $normalizedAlerts->values()->toArray(), 'categories' => $alert->categories ?? [], ], JSON_UNESCAPED_UNICODE); @endphp {{-- 勾選框 --}} {{-- 未讀紅點 --}} {{-- 案件編號 --}} {{-- 等級(只顯示一次) --}} {{-- 問題種類(類別標籤,緊接等級後) --}} {{-- 客戶(獨立欄) --}} {{-- 主機(獨立欄) --}} {{-- 摘要(最多 2 行,其餘點進去看) --}} {{-- 時間 --}} {{-- 操作 --}} @empty @endforelse
案件編號 等級{!! $sortIcon('level') !!} 問題種類 客戶{!! $sortIcon('client') !!} 主機{!! $sortIcon('host') !!} 摘要 時間{!! $sortIcon('time') !!}
@if(!$isRead) @endif {{ $caseNo }} {{ $levelBadge['label'] }}
@foreach($byCategory as $catKey => $catItems) @php $catDef = \App\Models\HostAlert::CATEGORIES[$catKey] ?? ['label'=>$catKey,'color'=>'secondary','icon'=>'bi-bell']; @endphp {{ $catDef['label'] }} @endforeach
@if($client) {{ $client->name }} @else @endif @if($host) {{ $host->name }} @if($host->ip_address) {{ $host->ip_address }} @endif @else 已刪除 @endif
@foreach($normalizedAlerts->take(2) as $ai)
{{ $ai['message'] }}
@endforeach @if($normalizedAlerts->count() > 2)
… 還有 {{ $normalizedAlerts->count()-2 }} 項
@endif
{{ $alert->created_at->format('Y/m/d H:i') }} {{ $alert->created_at->diffForHumans() }}
@if(!$isRead)
@csrf @method('PATCH')
@endif
@csrf @method('DELETE')
沒有符合條件的告警記錄
@if($alerts->hasPages()) @endif
{{-- ════════════════════════════════════════════════════ 告警詳細 Modal ════════════════════════════════════════════════════ --}} @push('scripts') @endpush @endsection