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:
@@ -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)) {
|
||||
|
||||
@@ -295,7 +295,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<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>
|
||||
<button
|
||||
@@ -326,10 +326,12 @@
|
||||
sortField: 'timestamp_iso',
|
||||
sortDirection: 'desc',
|
||||
initialize(initialLogs) {
|
||||
console.log('Initializing logs, received:', initialLogs ? initialLogs.length : 0, 'entries');
|
||||
this.logs = (initialLogs || []).map((log, index) => ({
|
||||
index,
|
||||
...log,
|
||||
}));
|
||||
console.log('Logs after initialization:', this.logs.length);
|
||||
},
|
||||
sort(field) {
|
||||
if (this.sortField === field) {
|
||||
|
||||
Reference in New Issue
Block a user