From 974688149263fce99e32da29599182b1c697da5d Mon Sep 17 00:00:00 2001 From: GraegelTh <165781231+GraegelTh@users.noreply.github.com> Date: Thu, 11 Dec 2025 15:24:13 +0100 Subject: [PATCH] Updated hostname MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hostname sollte jetzt statt 127.0.0.1 den tatsächlichen Hostnamen anzeigen --- app/Services/Snmp/SnmpServerStatusService.php | 19 ++++++++++++------- config/config.php | 1 + public/views/dashboard.php | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/Services/Snmp/SnmpServerStatusService.php b/app/Services/Snmp/SnmpServerStatusService.php index b75907e..9e4d5b9 100644 --- a/app/Services/Snmp/SnmpServerStatusService.php +++ b/app/Services/Snmp/SnmpServerStatusService.php @@ -67,7 +67,12 @@ class SnmpServerStatusService // Hilfsfunktion: SNMP-Werte bereinigen (z.B. "INTEGER: 123" -> 123) $cleanSnmpValue = fn($v) => (int)filter_var($v, FILTER_SANITIZE_NUMBER_INT); - // --- 2. Uptime abfragen --- + // --- 2. Hostname abfragen (dynamisch, nicht hardcoded) --- + $hostnameOid = $oids['hostname'] ?? '1.3.6.1.2.1.1.5.0'; // sysName OID + $hostnameResult = @snmpget($host, $community, $hostnameOid, $timeout, $retries); + $hostnameFromSnmp = $hostnameResult ? trim(str_ireplace('STRING:', '', $hostnameResult), ' "') : $host; + + // --- 3. Uptime abfragen --- $uptimeOid = $oids['uptime'] ?? '1.3.6.1.2.1.1.3.0'; $uptimeResult = @snmpget($host, $community, $uptimeOid, $timeout, $retries); if ($uptimeResult === false) { @@ -86,7 +91,7 @@ class SnmpServerStatusService (int)($uptimeSeconds % 60) ); - // --- 3. CPU (Durchschnitt über alle Kerne) --- + // --- 4. CPU (Durchschnitt über alle Kerne) --- $cpuTable = $oids['cpu_table'] ?? '1.3.6.1.2.1.25.3.3.1.2'; $cpuValues = @snmpwalk($host, $community, $cpuTable, $timeout, $retries); @@ -97,7 +102,7 @@ class SnmpServerStatusService $cpuValues = array_map($cleanSnmpValue, $cpuValues); $cpuAvg = (int)round(array_sum($cpuValues) / count($cpuValues)); - // --- 4. Storage-Tabellen (RAM + Disks) --- + // --- 5. Storage-Tabellen (RAM + Disks) --- $descrOid = $oids['storage_descr'] ?? '1.3.6.1.2.1.25.2.3.1.3'; $unitsOid = $oids['storage_units'] ?? '1.3.6.1.2.1.25.2.3.1.4'; $sizeOid = $oids['storage_size'] ?? '1.3.6.1.2.1.25.2.3.1.5'; @@ -118,7 +123,7 @@ class SnmpServerStatusService $size = array_map($cleanSnmpValue, $size); $used = array_map($cleanSnmpValue, $used); - // --- 5. RAM mit Fallback-Logik --- + // --- 6. RAM mit Fallback-Logik --- $ramPercent = null; $memTotalBytes = null; @@ -163,7 +168,7 @@ class SnmpServerStatusService throw new RuntimeException("Konnte 'Physical Memory' in der SNMP Storage-Tabelle nicht finden."); } - // --- 6. Disk C: / Root mit Fallback-Logik --- + // --- 7. Disk C: / Root mit Fallback-Logik --- $diskCPercent = null; // Heuristik 1: Suche nach C:\ @@ -212,9 +217,9 @@ class SnmpServerStatusService throw new RuntimeException("Konnte Laufwerk 'C:\\' oder Root-Partition in der SNMP Storage-Tabelle nicht finden."); } - // --- 7. Status-Array zusammenbauen --- + // --- 8. Status-Array zusammenbauen --- $status = [ - 'hostname' => $host, + 'hostname' => $hostnameFromSnmp, 'os' => 'Windows Server', // TODO: OS dynamisch per SNMP abfragen (OID 1.3.6.1.2.1.1.1.0) 'uptime' => $uptimeFormatted, 'cpu_usage' => $cpuAvg, diff --git a/config/config.php b/config/config.php index aebf7fe..a65cdb3 100644 --- a/config/config.php +++ b/config/config.php @@ -36,6 +36,7 @@ return [ // Platzhalter für OIDs – später können wir die auf echte Werte setzen 'oids' => [ + 'hostname' => '1.3.6.1.2.1.1.5.0', // sysName - Hostname des Servers 'uptime' => '1.3.6.1.2.1.1.3.0', // CPU pro Kern diff --git a/public/views/dashboard.php b/public/views/dashboard.php index d2c2026..91845a5 100644 --- a/public/views/dashboard.php +++ b/public/views/dashboard.php @@ -153,6 +153,7 @@ declare(strict_types=1);