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
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user