This commit is contained in:
Thomas Peterson 2025-11-17 10:30:58 +01:00
parent b07058f742
commit 162686739e
2 changed files with 61 additions and 7 deletions

View File

@ -27,6 +27,10 @@ class HetznerService
'status' => $server->status,
'type' => $server->serverType->name,
'ipv4' => $server->publicNet->ipv4->ip,
'docker_status' => 'pending',
'domains' => [],
'needs_reboot' => 'unbekannt',
'updates_available' => 'unbekannt',
];
}
@ -55,6 +59,8 @@ class HetznerService
'ipv4' => sprintf('192.168.%d.%d', floor($i / 255), $i % 255),
'docker_status' => 'pending',
'domains' => [],
'needs_reboot' => 'nein',
'updates_available' => 'nein',
];
}
return $testData;

View File

@ -86,7 +86,9 @@ class ServerListTab
['key' => 'status', 'title' => 'Status', 'width' => 100],
['key' => 'type', 'title' => 'Typ', 'width' => 80],
['key' => 'ipv4', 'title' => 'IPv4', 'width' => 160],
['key' => 'docker_status', 'title' => 'Docker', 'width' => 100],
['key' => 'docker_status', 'title' => 'Docker', 'width' => 90],
['key' => 'needs_reboot', 'title' => 'Neustart', 'width' => 90],
['key' => 'updates_available', 'title' => 'Updates', 'width' => 130],
]);
// Load initial test data
@ -275,16 +277,24 @@ class ServerListTab
echo "Error: {$result['error']}\n";
} elseif (isset($result['success'], $result['servers'])) {
// Basisdaten setzen, Docker-Status initial auf "pending"
$serverListTab->currentServerData = array_map(static fn($row) => array_merge([
'docker_status' => 'pending',
'docker' => null,
'docker_error' => null,
], $row), $result['servers']);
$serverListTab->currentServerData = array_map(
static fn($row) => array_merge(
[
'docker_status' => 'pending',
'docker' => null,
'docker_error' => null,
'needs_reboot' => 'unbekannt',
'updates_available' => 'unbekannt',
],
$row,
),
$result['servers'],
);
$serverListTab->table->setData($serverListTab->currentServerData);
$serverListTab->statusLabel->setText('Server geladen: ' . $result['count'] . ' gefunden');
// Danach: pro Server asynchron Docker-Infos nachladen
// Danach: pro Server asynchron Docker-Infos und Systemstatus nachladen
foreach ($serverListTab->currentServerData as $index => $row) {
$ip = $row['ipv4'] ?? '';
@ -315,6 +325,19 @@ class ServerListTab
];
}
// Check if reboot is required (Ubuntu)
$rebootOutput = trim($ssh->exec(
'[ -f /var/run/reboot-required ] && echo yes || echo no',
));
$needsReboot = ($rebootOutput === 'yes');
// Check number of available package updates (Ubuntu)
$updatesOutput = trim($ssh->exec(
'apt-get -s upgrade 2>/dev/null | grep -c "^Inst " || echo 0',
));
$updatesCount = is_numeric($updatesOutput) ? (int) $updatesOutput : 0;
// Docker status for main application container
$output = $ssh->exec('docker inspect psc-web-1');
if (empty($output)) {
@ -323,6 +346,8 @@ class ServerListTab
'docker' => null,
'docker_error' => 'Leere Docker-Antwort',
'docker_status' => 'error',
'needs_reboot' => $needsReboot,
'updates' => $updatesCount,
];
}
@ -333,6 +358,8 @@ class ServerListTab
'docker' => null,
'docker_error' => 'Ungültige Docker-JSON-Antwort',
'docker_status' => 'error',
'needs_reboot' => $needsReboot,
'updates' => $updatesCount,
];
}
@ -341,6 +368,8 @@ class ServerListTab
'docker' => $json,
'docker_error' => null,
'docker_status' => 'ok',
'needs_reboot' => $needsReboot,
'updates' => $updatesCount,
];
} catch (\Throwable $e) {
return [
@ -348,6 +377,8 @@ class ServerListTab
'docker' => null,
'docker_error' => 'SSH-Fehler: ' . $e->getMessage(),
'docker_status' => 'error',
'needs_reboot' => null,
'updates' => null,
];
}
});
@ -384,6 +415,23 @@ class ServerListTab
$serverListTab->table->setData($serverListTab->currentServerData);
}
// Map system status into human-readable table fields
if (array_key_exists('needs_reboot', $dockerResult)) {
$needsReboot = $dockerResult['needs_reboot'];
if ($needsReboot === null) {
$serverListTab->currentServerData[$i]['needs_reboot'] = 'unbekannt';
} else {
$serverListTab->currentServerData[$i]['needs_reboot'] =
$needsReboot ? 'ja' : 'nein';
}
}
if (array_key_exists('updates', $dockerResult)) {
$updates = (int) ($dockerResult['updates'] ?? 0);
$serverListTab->currentServerData[$i]['updates_available'] =
$updates > 0 ? ('ja (' . $updates . ')') : 'nein';
}
if (array_key_exists('docker_error', $dockerResult)) {
$serverListTab->currentServerData[$i]['docker_error'] =
$dockerResult['docker_error'];