refactor: enhance Proxmox Firewall log handling by adding log start parameter and improving log processing, including detailed logging of fetched data

This commit is contained in:
2025-12-02 17:01:09 -05:00
parent 3f28a92ece
commit ba242f8f78
2 changed files with 18 additions and 5 deletions

View File

@@ -802,7 +802,10 @@ class Firewall extends Component
$response = $this->firewallRequest(
'/nodes/' . $this->server->node->name . '/qemu/' . $this->server->vm_id . '/firewall/log',
'get',
['limit' => $this->logLimit]
[
'limit' => $this->logLimit,
'start' => 0
]
);
if (! $response->successful()) {
@@ -830,18 +833,21 @@ class Firewall extends Component
$rawLogs = [];
if (! empty($body)) {
// Split by newlines and filter empty lines
$lines = explode("\n", trim($body));
// Split by newlines (handle both \n and \r\n)
$lines = preg_split('/\r\n|\r|\n/', $body);
$rawLogs = array_filter($lines, static function ($line) {
return ! empty(trim($line));
});
// Re-index array after filtering
$rawLogs = array_values($rawLogs);
}
\Log::debug('Firewall logs fetched from Proxmox API', [
\Log::info('Firewall logs fetched from Proxmox API', [
'raw_count' => count($rawLogs),
'body_length' => strlen($body),
'content_type' => $response->header('Content-Type'),
'sample' => ! empty($rawLogs) ? substr($rawLogs[array_key_first($rawLogs)], 0, 200) : null,
'first_5_lines' => array_slice($rawLogs, 0, 5),
]);
$this->firewallLogs = [];
@@ -871,6 +877,11 @@ class Firewall extends Component
$this->firewallLogs[] = $this->parseFirewallLog($logText);
}
\Log::info('Firewall logs final count', [
'total_logs' => count($this->firewallLogs),
'first_3_sources' => array_slice(array_column($this->firewallLogs, 'source'), 0, 3),
]);
if (empty($this->firewallLogs) && ! empty($rawLogs)) {
$this->logError = 'Logs received but could not be processed.';
} elseif (empty($this->firewallLogs)) {