72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Hosting\Health;
|
|
|
|
use App\Services\Hosting\Proxmox\ProxmoxClient;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
class SystemHealthService
|
|
{
|
|
public function __construct(private readonly ProxmoxClient $proxmox) {}
|
|
|
|
/**
|
|
* @return array<string, array{status: string, message: string}>
|
|
*/
|
|
public function checks(): array
|
|
{
|
|
return [
|
|
'database' => $this->checkDatabase(),
|
|
'proxmox' => $this->checkProxmox(),
|
|
'traefik_config' => $this->checkTraefik(),
|
|
'queue' => $this->checkQueue(),
|
|
];
|
|
}
|
|
|
|
private function checkDatabase(): array
|
|
{
|
|
try {
|
|
DB::connection()->getPdo();
|
|
|
|
return ['status' => 'ok', 'message' => 'Datenbank erreichbar'];
|
|
} catch (\Throwable $e) {
|
|
return ['status' => 'error', 'message' => $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
private function checkProxmox(): array
|
|
{
|
|
try {
|
|
$this->proxmox->node();
|
|
|
|
return ['status' => 'ok', 'message' => 'Proxmox API erreichbar'];
|
|
} catch (\Throwable $e) {
|
|
return ['status' => 'error', 'message' => $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
private function checkTraefik(): array
|
|
{
|
|
$path = config('hosting.traefik.dynamic_config_path');
|
|
if (! $path) {
|
|
return ['status' => 'warning', 'message' => 'Traefik-Pfad nicht konfiguriert'];
|
|
}
|
|
if (! is_writable(dirname($path)) && ! file_exists($path)) {
|
|
return ['status' => 'warning', 'message' => 'Traefik-Verzeichnis nicht beschreibbar'];
|
|
}
|
|
|
|
return ['status' => 'ok', 'message' => is_file($path) ? 'Konfigurationsdatei vorhanden' : 'Wird bei erster Route angelegt'];
|
|
}
|
|
|
|
private function checkQueue(): array
|
|
{
|
|
try {
|
|
$size = DB::table('jobs')->count();
|
|
|
|
return ['status' => 'ok', 'message' => "Queue: {$size} ausstehende Jobs"];
|
|
} catch (\Throwable) {
|
|
return ['status' => 'warning', 'message' => 'Queue-Tabelle nicht verfügbar (sync driver?)'];
|
|
}
|
|
}
|
|
}
|