From 0bdbd7b224cc98178a94ed964381345ecb3af7c7 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Tue, 2 Dec 2025 07:30:46 -0500 Subject: [PATCH] refactor: improve firewall log processing in Proxmox component by enhancing log parsing, adding debug logging for parsed entries, and ensuring proper array handling for better clarity and debugging --- .../Servers/Proxmox/Livewire/Firewall.php | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/extensions/Servers/Proxmox/Livewire/Firewall.php b/extensions/Servers/Proxmox/Livewire/Firewall.php index 21717b099..9cd3f6475 100644 --- a/extensions/Servers/Proxmox/Livewire/Firewall.php +++ b/extensions/Servers/Proxmox/Livewire/Firewall.php @@ -838,11 +838,13 @@ 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', [ @@ -850,11 +852,12 @@ class Firewall extends Component '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 = []; - foreach ($rawLogs as $logEntry) { + foreach ($rawLogs as $index => $logEntry) { $logText = ''; if (is_string($logEntry)) { @@ -876,9 +879,25 @@ class Firewall extends Component continue; } - $this->firewallLogs[] = $this->parseFirewallLog($logText); + $parsedLog = $this->parseFirewallLog($logText); + $this->firewallLogs[] = $parsedLog; + + // Debug first few parsed logs + if ($index < 3) { + \Log::debug('Parsed firewall log entry', [ + 'index' => $index, + 'raw' => substr($logText, 0, 200), + 'parsed' => $parsedLog, + ]); + } } + \Log::debug('Firewall logs processing complete', [ + 'raw_logs_count' => count($rawLogs), + 'parsed_logs_count' => count($this->firewallLogs), + 'sample_parsed_logs' => array_slice($this->firewallLogs, 0, 3), + ]); + if (empty($this->firewallLogs) && ! empty($rawLogs)) { $this->logError = 'Logs received but could not be processed.'; } elseif (empty($this->firewallLogs)) {