Co-authored-by: Tom <165781231+GraegelTh@users.noreply.github.com> Reviewed-on: https://git.eckertplayground.de/taarly/PHP_AdminTool_Projekt/pulls/14
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Services\Snmp\SnmpServerStatusService;
|
|
|
|
/**
|
|
* Controller für das Dashboard.
|
|
*
|
|
* Zeigt Serverstatus-Metriken über SNMP an:
|
|
* - Initial Load: Server-seitiger Service-Aufruf (sofortige Daten)
|
|
* - Live-Updates: Client-seitiges JavaScript-Polling alle 5s
|
|
*/
|
|
class DashboardController
|
|
{
|
|
private array $config;
|
|
private SnmpServerStatusService $snmpService;
|
|
|
|
public function __construct(array $config)
|
|
{
|
|
$this->config = $config;
|
|
$snmpConfig = $config['snmp'] ?? [];
|
|
$this->snmpService = new SnmpServerStatusService($snmpConfig);
|
|
}
|
|
|
|
/**
|
|
* Zeigt das Dashboard an.
|
|
*
|
|
* Beim initialen Laden wird der Service aufgerufen, um sofort Daten anzuzeigen.
|
|
* Live-Updates erfolgen anschließend via JavaScript-Polling (api/snmp_status.php alle 5s).
|
|
*/
|
|
public function show(): array
|
|
{
|
|
$serverStatus = [
|
|
'hostname' => 'n/a',
|
|
'os' => 'n/a',
|
|
'uptime' => 'n/a',
|
|
'cpu_usage' => 0,
|
|
'memory_usage' => 0,
|
|
'disk_usage_c' => 0,
|
|
'last_update' => date('d.m.Y H:i:s'),
|
|
];
|
|
|
|
try {
|
|
$serverStatus = $this->snmpService->getServerStatus();
|
|
} catch (\RuntimeException $e) {
|
|
error_log('DashboardController: SNMP-Fehler beim initialen Laden - ' . $e->getMessage());
|
|
}
|
|
|
|
$viewPath = __DIR__ . '/../../public/views/dashboard.php';
|
|
|
|
return [
|
|
'view' => $viewPath,
|
|
'data' => [
|
|
'serverStatus' => $serverStatus,
|
|
'loginPage' => false,
|
|
],
|
|
'pageTitle' => 'Dashboard',
|
|
'activeMenu' => 'dashboard',
|
|
];
|
|
}
|
|
}
|