diff --git a/app/Jobs/RunHealthChecks.php b/app/Jobs/RunHealthChecks.php index 1f87aa9..60721bd 100644 --- a/app/Jobs/RunHealthChecks.php +++ b/app/Jobs/RunHealthChecks.php @@ -3,6 +3,7 @@ namespace App\Jobs; use App\Support\CacheVer; +use App\Support\Setting; use App\Support\WoltGuard\Probes; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; @@ -31,7 +32,12 @@ class RunHealthChecks implements ShouldQueue $svcRows[] = ['name' => $key, 'ok' => $ok]; // labels brauchst du im UI } - Cache::put(CacheVer::k('health:services'), $svcRows, 60); +// Cache::put(CacheVer::k('health:services'), $svcRows, 60); + Cache::put(CacheVer::k('health:services'), [ + 'ts' => time(), + 'rows' => $svcRows, + ], 300); + Setting::set('woltguard.services', ['ts' => time(), 'rows' => $svcRows]); Cache::forget('health:services'); } diff --git a/app/Livewire/Ui/System/WoltguardCard.php b/app/Livewire/Ui/System/WoltguardCard.php index fbcb082..4f3b2ad 100644 --- a/app/Livewire/Ui/System/WoltguardCard.php +++ b/app/Livewire/Ui/System/WoltguardCard.php @@ -3,6 +3,7 @@ namespace App\Livewire\Ui\System; use App\Support\CacheVer; +use App\Support\Setting; use Illuminate\Support\Facades\Cache; use Livewire\Component; @@ -47,27 +48,34 @@ class WoltguardCard extends Component protected function load(): void { - // 1) Primär: versionierter Key - $list = Cache::get(CacheVer::k('health:services'), []); - // 2) Fallback: Legacy-Key (nur falls 1) leer) - if (empty($list)) { - $list = Cache::get('health:services', []); + // 1) Primär: Redis + $data = Cache::get(CacheVer::k('health:services')); + + // 2) Fallback: Settings (DB) + if (!is_array($data) || empty($data['rows'])) { + $data = Setting::get('woltguard.services', []); } - $this->services = is_array($list) ? $list : []; + // 3) Falls beides leer → letzter bekannter Zustand beibehalten + $rows = $data['rows'] ?? []; + if (empty($rows) && !empty($this->services)) { + $rows = $this->services; + } - $this->totalCount = count($this->services); - $this->okCount = collect($this->services)->filter(fn($s) => (bool)($s['ok'] ?? false))->count(); - $this->downCount = $this->totalCount - $this->okCount; + // Mapping + $this->services = $rows; + $this->totalCount = count($rows); + $this->okCount = collect($rows)->where('ok', true)->count(); + $this->downCount = max(0, $this->totalCount - $this->okCount); $this->guardOk = ($this->totalCount > 0) && ($this->downCount === 0); - $this->downServices = collect($this->services) + $this->downServices = collect($rows) ->filter(fn($s) => !($s['ok'] ?? false)) ->map(fn($s) => (string)($s['name'] ?? 'unbekannt')) ->values() ->all(); - // Badge + // Badges if ($this->totalCount === 0) { $this->badgeText = 'keine Daten'; $this->badgeIcon = 'ph ph-warning-circle'; @@ -92,6 +100,53 @@ class WoltguardCard extends Component } } } +// protected function load(): void +// { +// // 1) Primär: versionierter Key +// $list = Cache::get(CacheVer::k('health:services'), []); +// // 2) Fallback: Legacy-Key (nur falls 1) leer) +// if (empty($list)) { +// $list = Cache::get('health:services', []); +// } +// +// $this->services = is_array($list) ? $list : []; +// +// $this->totalCount = count($this->services); +// $this->okCount = collect($this->services)->filter(fn($s) => (bool)($s['ok'] ?? false))->count(); +// $this->downCount = $this->totalCount - $this->okCount; +// $this->guardOk = ($this->totalCount > 0) && ($this->downCount === 0); +// +// $this->downServices = collect($this->services) +// ->filter(fn($s) => !($s['ok'] ?? false)) +// ->map(fn($s) => (string)($s['name'] ?? 'unbekannt')) +// ->values() +// ->all(); +// +// // Badge +// if ($this->totalCount === 0) { +// $this->badgeText = 'keine Daten'; +// $this->badgeIcon = 'ph ph-warning-circle'; +// $this->badgeClass = 'text-amber-300 border-amber-400/30 bg-amber-500/10'; +// return; +// } +// +// if ($this->guardOk) { +// $this->badgeText = 'alle Dienste OK'; +// $this->badgeIcon = 'ph ph-check-circle'; +// $this->badgeClass = 'text-emerald-300 border-emerald-400/30 bg-emerald-500/10'; +// } else { +// if ($this->downCount >= 3) { +// $this->badgeText = "{$this->downCount} Dienste down"; +// $this->badgeIcon = 'ph ph-x-circle'; +// $this->badgeClass = 'text-rose-300 border-rose-400/30 bg-rose-500/10'; +// } else { +// $this->badgeText = 'Störung erkannt'; +// $this->badgeIcon = 'ph ph-warning-circle'; +// $this->badgeClass = 'text-amber-300 border-amber-400/30 bg-amber-500/10'; +// } +// } +// } +//} // //namespace App\Livewire\Ui\System; diff --git a/routes/console.php b/routes/console.php index 84d121d..3354e7a 100644 --- a/routes/console.php +++ b/routes/console.php @@ -9,7 +9,7 @@ Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); -Schedule::job(RunHealthChecks::class)->everyFiveMinutes()->withoutOverlapping(); +Schedule::job(RunHealthChecks::class)->everyMinute()->withoutOverlapping()->onOneServer(); Schedule::command('spamav:collect')->everyFiveMinutes()->withoutOverlapping(); //Schedule::command('woltguard:collect-services')->everyMinute(); //Schedule::command('mailwolt:check-updates')->dailyAt('04:10');