Private
Public Access
1
0

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

View File

@@ -295,7 +295,7 @@
</div> </div>
<div> <div>
<h2 class="text-xl font-semibold">Firewall Logs</h2> <h2 class="text-xl font-semibold">Firewall Logs</h2>
<p class="text-sm text-base/60 mt-1">Recent firewall activity and blocked/allowed connections</p> <p class="text-sm text-base/60 mt-1">Recent firewall activity and blocked/allowed connections ({{ count($firewallLogs) }} entries loaded)</p>
</div> </div>
</div> </div>
<button <button
@@ -326,10 +326,12 @@
sortField: 'timestamp_iso', sortField: 'timestamp_iso',
sortDirection: 'desc', sortDirection: 'desc',
initialize(initialLogs) { initialize(initialLogs) {
console.log('Initializing logs, received:', initialLogs ? initialLogs.length : 0, 'entries');
this.logs = (initialLogs || []).map((log, index) => ({ this.logs = (initialLogs || []).map((log, index) => ({
index, index,
...log, ...log,
})); }));
console.log('Logs after initialization:', this.logs.length);
}, },
sort(field) { sort(field) {
if (this.sortField === field) { if (this.sortField === field) {