parent
7e5a9a42d5
commit
8d5cf8b3c5
|
|
@ -6,7 +6,6 @@ use App\Support\CacheVer;
|
||||||
use App\Support\WoltGuard\Probes;
|
use App\Support\WoltGuard\Probes;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Queue\Queueable;
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Livewire\Ui\System;
|
||||||
|
|
||||||
use App\Support\CacheVer;
|
use App\Support\CacheVer;
|
||||||
use App\Support\WoltGuard\Probes;
|
use App\Support\WoltGuard\Probes;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
@ -44,27 +45,35 @@ class ServicesCard extends Component
|
||||||
|
|
||||||
public function load(): void
|
public function load(): void
|
||||||
{
|
{
|
||||||
|
// 1) Karten aus Config laden
|
||||||
$cards = config('woltguard.cards', []);
|
$cards = config('woltguard.cards', []);
|
||||||
|
|
||||||
$raw = Cache::get(CacheVer::k('health:services'), []);
|
if (empty($cards)) {
|
||||||
|
// Config-Clear/-Cache synchron ausführen (kostet ~ms)
|
||||||
// einmaliger Fallback für ältere Deploys:
|
try {
|
||||||
if (empty($raw)) {
|
Artisan::call('config:clear');
|
||||||
$raw = Cache::get('health:services', []);
|
Artisan::call('config:cache');
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// ignoriere – UI soll trotzdem laufen
|
||||||
|
}
|
||||||
|
$cards = config('woltguard.cards', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2) Service-Status aus Cache (versionierter Key)
|
||||||
|
$key = \App\Support\CacheVer::k('health:services');
|
||||||
|
$raw = Cache::get($key, []);
|
||||||
|
// Legacy-Key als Fallback
|
||||||
|
if (empty($raw)) $raw = Cache::get('health:services', []);
|
||||||
|
|
||||||
$cached = collect($raw)->keyBy('name');
|
$cached = collect($raw)->keyBy('name');
|
||||||
|
|
||||||
$rows = [];
|
$rows = [];
|
||||||
$ok = 0;
|
$ok = 0;
|
||||||
$total = 0;
|
|
||||||
|
|
||||||
foreach ($cards as $key => $card) {
|
foreach ($cards as $name => $card) {
|
||||||
$total++;
|
$isOk = (bool) ($cached->get($name)['ok'] ?? false);
|
||||||
// 1) Cache-Hit?
|
|
||||||
$isOk = (bool) ($cached->get($key)['ok'] ?? false);
|
|
||||||
|
|
||||||
// 2) Fallback probe (falls Cache leer/alt)
|
// 3) Wenn Cache leer → aktiv prüfen
|
||||||
if ($cached->isEmpty()) {
|
if ($cached->isEmpty()) {
|
||||||
foreach ($card['sources'] as $src) {
|
foreach ($card['sources'] as $src) {
|
||||||
if ($this->check($src)) { $isOk = true; break; }
|
if ($this->check($src)) { $isOk = true; break; }
|
||||||
|
|
@ -74,14 +83,22 @@ class ServicesCard extends Component
|
||||||
if ($isOk) $ok++;
|
if ($isOk) $ok++;
|
||||||
|
|
||||||
$rows[] = [
|
$rows[] = [
|
||||||
'label' => $card['label'],
|
'name' => $name, // <— wichtig, damit der Cache keyBy('name') später klappt
|
||||||
'hint' => $card['hint'],
|
'label' => $card['label'] ?? $name,
|
||||||
|
'hint' => $card['hint'] ?? null,
|
||||||
'ok' => $isOk,
|
'ok' => $isOk,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4) Wenn wir aktiv geprüft haben (Cache war leer) → Cache auffüllen
|
||||||
|
if ($cached->isEmpty() && !empty($rows)) {
|
||||||
|
Cache::put($key, $rows, 600); // 10 Minuten
|
||||||
|
Cache::forget('health:services'); // Legacy aufräumen
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5) Kopfzahlen + UI-Daten
|
||||||
$this->totalCount = count($rows);
|
$this->totalCount = count($rows);
|
||||||
$this->okCount = collect($rows)->where('ok', true)->count();
|
$this->okCount = $ok;
|
||||||
$this->guardOk = $this->totalCount > 0 && $this->okCount === $this->totalCount;
|
$this->guardOk = $this->totalCount > 0 && $this->okCount === $this->totalCount;
|
||||||
|
|
||||||
[$this->badgeText, $this->badgeClass, $this->badgeIcon] =
|
[$this->badgeText, $this->badgeClass, $this->badgeIcon] =
|
||||||
|
|
@ -89,17 +106,78 @@ class ServicesCard extends Component
|
||||||
? ['alle Dienste OK', 'text-emerald-200 bg-emerald-500/10 border-emerald-400/30', 'ph ph-check-circle']
|
? ['alle Dienste OK', 'text-emerald-200 bg-emerald-500/10 border-emerald-400/30', 'ph ph-check-circle']
|
||||||
: ["{$this->okCount}/{$this->totalCount} aktiv", 'text-amber-200 bg-amber-500/10 border-amber-400/30', 'ph ph-warning'];
|
: ["{$this->okCount}/{$this->totalCount} aktiv", 'text-amber-200 bg-amber-500/10 border-amber-400/30', 'ph ph-warning'];
|
||||||
|
|
||||||
$this->servicesCompact = collect($rows)->map(fn($row) => [
|
$this->servicesCompact = collect($rows)->map(fn($r) => [
|
||||||
'label' => $row['label'],
|
'label' => $r['label'],
|
||||||
'hint' => $row['hint'],
|
'hint' => $r['hint'],
|
||||||
'ok' => $row['ok'],
|
'ok' => $r['ok'],
|
||||||
'dotClass' => $row['ok'] ? 'bg-emerald-400' : 'bg-rose-400',
|
'dotClass' => $r['ok'] ? 'bg-emerald-400' : 'bg-rose-400',
|
||||||
'pillText' => $row['ok'] ? 'Online' : 'Offline',
|
'pillText' => $r['ok'] ? 'Online' : 'Offline',
|
||||||
'pillClass' => $row['ok']
|
'pillClass' => $r['ok']
|
||||||
? 'text-emerald-300 border-emerald-400/30 bg-emerald-500/10'
|
? 'text-emerald-300 border-emerald-400/30 bg-emerald-500/10'
|
||||||
: 'text-rose-300 border-rose-400/30 bg-rose-500/10',
|
: 'text-rose-300 border-rose-400/30 bg-rose-500/10',
|
||||||
])->all();
|
])->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function load(): void
|
||||||
|
// {
|
||||||
|
// $cards = config('woltguard.cards', []);
|
||||||
|
//
|
||||||
|
// $raw = Cache::get(CacheVer::k('health:services'), []);
|
||||||
|
//
|
||||||
|
// // einmaliger Fallback für ältere Deploys:
|
||||||
|
// if (empty($raw)) {
|
||||||
|
// $raw = Cache::get('health:services', []);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $cached = collect($raw)->keyBy('name');
|
||||||
|
//
|
||||||
|
// $rows = [];
|
||||||
|
// $ok = 0;
|
||||||
|
// $total = 0;
|
||||||
|
//
|
||||||
|
// foreach ($cards as $key => $card) {
|
||||||
|
// $total++;
|
||||||
|
// // 1) Cache-Hit?
|
||||||
|
// $isOk = (bool) ($cached->get($key)['ok'] ?? false);
|
||||||
|
//
|
||||||
|
// // 2) Fallback probe (falls Cache leer/alt)
|
||||||
|
// if ($cached->isEmpty()) {
|
||||||
|
// foreach ($card['sources'] as $src) {
|
||||||
|
// if ($this->check($src)) { $isOk = true; break; }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if ($isOk) $ok++;
|
||||||
|
//
|
||||||
|
// $rows[] = [
|
||||||
|
// 'label' => $card['label'],
|
||||||
|
// 'hint' => $card['hint'],
|
||||||
|
// 'ok' => $isOk,
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $this->totalCount = count($rows);
|
||||||
|
// $this->okCount = collect($rows)->where('ok', true)->count();
|
||||||
|
// $this->guardOk = $this->totalCount > 0 && $this->okCount === $this->totalCount;
|
||||||
|
//
|
||||||
|
// [$this->badgeText, $this->badgeClass, $this->badgeIcon] =
|
||||||
|
// $this->guardOk
|
||||||
|
// ? ['alle Dienste OK', 'text-emerald-200 bg-emerald-500/10 border-emerald-400/30', 'ph ph-check-circle']
|
||||||
|
// : ["{$this->okCount}/{$this->totalCount} aktiv", 'text-amber-200 bg-amber-500/10 border-amber-400/30', 'ph ph-warning'];
|
||||||
|
//
|
||||||
|
// $this->servicesCompact = collect($rows)->map(fn($row) => [
|
||||||
|
// 'label' => $row['label'],
|
||||||
|
// 'hint' => $row['hint'],
|
||||||
|
// 'ok' => $row['ok'],
|
||||||
|
// 'dotClass' => $row['ok'] ? 'bg-emerald-400' : 'bg-rose-400',
|
||||||
|
// 'pillText' => $row['ok'] ? 'Online' : 'Offline',
|
||||||
|
// 'pillClass' => $row['ok']
|
||||||
|
// ? 'text-emerald-300 border-emerald-400/30 bg-emerald-500/10'
|
||||||
|
// : 'text-rose-300 border-rose-400/30 bg-rose-500/10',
|
||||||
|
// ])->all();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// public function load(): void
|
// public function load(): void
|
||||||
// {
|
// {
|
||||||
// // Cache nur als optionaler Beschleuniger für Einzel-Checks,
|
// // Cache nur als optionaler Beschleuniger für Einzel-Checks,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
return [
|
return [
|
||||||
'units' => [
|
'units' => [
|
||||||
['name' => 'nginx', 'action' => 'reload'],
|
['name' => 'nginx', 'action' => 'reload'],
|
||||||
['name' => 'php8.2-fpm', 'action' => 'restart'],
|
// ['name' => 'php8.2-fpm', 'action' => 'restart'],
|
||||||
['name' => 'postfix', 'action' => 'try-reload-or-restart'],
|
['name' => 'postfix', 'action' => 'try-reload-or-restart'],
|
||||||
['name' => 'dovecot', 'action' => 'try-reload-or-restart'],
|
['name' => 'dovecot', 'action' => 'try-reload-or-restart'],
|
||||||
['name' => 'rspamd', 'action' => 'try-reload-or-restart'],
|
['name' => 'rspamd', 'action' => 'try-reload-or-restart'],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue