Updated hostname
Hostname sollte jetzt statt 127.0.0.1 den tatsächlichen Hostnamen anzeigen
This commit is contained in:
parent
a639cd68e3
commit
9746881492
@ -67,7 +67,12 @@ class SnmpServerStatusService
|
|||||||
// Hilfsfunktion: SNMP-Werte bereinigen (z.B. "INTEGER: 123" -> 123)
|
// Hilfsfunktion: SNMP-Werte bereinigen (z.B. "INTEGER: 123" -> 123)
|
||||||
$cleanSnmpValue = fn($v) => (int)filter_var($v, FILTER_SANITIZE_NUMBER_INT);
|
$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';
|
$uptimeOid = $oids['uptime'] ?? '1.3.6.1.2.1.1.3.0';
|
||||||
$uptimeResult = @snmpget($host, $community, $uptimeOid, $timeout, $retries);
|
$uptimeResult = @snmpget($host, $community, $uptimeOid, $timeout, $retries);
|
||||||
if ($uptimeResult === false) {
|
if ($uptimeResult === false) {
|
||||||
@ -86,7 +91,7 @@ class SnmpServerStatusService
|
|||||||
(int)($uptimeSeconds % 60)
|
(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';
|
$cpuTable = $oids['cpu_table'] ?? '1.3.6.1.2.1.25.3.3.1.2';
|
||||||
$cpuValues = @snmpwalk($host, $community, $cpuTable, $timeout, $retries);
|
$cpuValues = @snmpwalk($host, $community, $cpuTable, $timeout, $retries);
|
||||||
|
|
||||||
@ -97,7 +102,7 @@ class SnmpServerStatusService
|
|||||||
$cpuValues = array_map($cleanSnmpValue, $cpuValues);
|
$cpuValues = array_map($cleanSnmpValue, $cpuValues);
|
||||||
$cpuAvg = (int)round(array_sum($cpuValues) / count($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';
|
$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';
|
$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';
|
$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);
|
$size = array_map($cleanSnmpValue, $size);
|
||||||
$used = array_map($cleanSnmpValue, $used);
|
$used = array_map($cleanSnmpValue, $used);
|
||||||
|
|
||||||
// --- 5. RAM mit Fallback-Logik ---
|
// --- 6. RAM mit Fallback-Logik ---
|
||||||
$ramPercent = null;
|
$ramPercent = null;
|
||||||
$memTotalBytes = null;
|
$memTotalBytes = null;
|
||||||
|
|
||||||
@ -163,7 +168,7 @@ class SnmpServerStatusService
|
|||||||
throw new RuntimeException("Konnte 'Physical Memory' in der SNMP Storage-Tabelle nicht finden.");
|
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;
|
$diskCPercent = null;
|
||||||
|
|
||||||
// Heuristik 1: Suche nach C:\
|
// 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.");
|
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 = [
|
$status = [
|
||||||
'hostname' => $host,
|
'hostname' => $hostnameFromSnmp,
|
||||||
'os' => 'Windows Server', // TODO: OS dynamisch per SNMP abfragen (OID 1.3.6.1.2.1.1.1.0)
|
'os' => 'Windows Server', // TODO: OS dynamisch per SNMP abfragen (OID 1.3.6.1.2.1.1.1.0)
|
||||||
'uptime' => $uptimeFormatted,
|
'uptime' => $uptimeFormatted,
|
||||||
'cpu_usage' => $cpuAvg,
|
'cpu_usage' => $cpuAvg,
|
||||||
|
|||||||
@ -36,6 +36,7 @@ return [
|
|||||||
|
|
||||||
// Platzhalter für OIDs – später können wir die auf echte Werte setzen
|
// Platzhalter für OIDs – später können wir die auf echte Werte setzen
|
||||||
'oids' => [
|
'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',
|
'uptime' => '1.3.6.1.2.1.1.3.0',
|
||||||
|
|
||||||
// CPU pro Kern
|
// CPU pro Kern
|
||||||
|
|||||||
@ -153,6 +153,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function(){
|
document.addEventListener('DOMContentLoaded', function(){
|
||||||
|
const hostnameEl = document.querySelector('.col-xl-3:first-child .h5.mb-0'); // Hostname card (first card)
|
||||||
const diskEl = document.getElementById('disk_usage_text');
|
const diskEl = document.getElementById('disk_usage_text');
|
||||||
const uptimeEl = document.getElementById('uptime_text');
|
const uptimeEl = document.getElementById('uptime_text');
|
||||||
const cpuEl = document.getElementById('cpu_card_value');
|
const cpuEl = document.getElementById('cpu_card_value');
|
||||||
@ -161,6 +162,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||||||
|
|
||||||
function updateUI(data){
|
function updateUI(data){
|
||||||
if(!data) return;
|
if(!data) return;
|
||||||
|
if(hostnameEl) hostnameEl.textContent = data.hostname || 'n/a';
|
||||||
if(diskEl) diskEl.textContent = (data.disk_usage_c !== null && data.disk_usage_c !== undefined) ? Math.round(data.disk_usage_c) : 'n/a';
|
if(diskEl) diskEl.textContent = (data.disk_usage_c !== null && data.disk_usage_c !== undefined) ? Math.round(data.disk_usage_c) : 'n/a';
|
||||||
if(uptimeEl) uptimeEl.textContent = data.uptime || 'n/a';
|
if(uptimeEl) uptimeEl.textContent = data.uptime || 'n/a';
|
||||||
if(cpuEl) cpuEl.textContent = (data.cpu_usage !== null && data.cpu_usage !== undefined) ? Math.round(data.cpu_usage) : 0;
|
if(cpuEl) cpuEl.textContent = (data.cpu_usage !== null && data.cpu_usage !== undefined) ? Math.round(data.cpu_usage) : 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user