Skip to content

Commit e7fcd04

Browse files
committed
Fix inactive status passing empty array to view template
The livestats.blade.php view requires variables like $vm_running, $cpu_percent, etc. When returning "inactive" status, we were passing an empty array which caused undefined variable errors. Now passing $inactiveData with default zero values so the view renders properly even when the API is unreachable or returns no data.
1 parent d89f080 commit e7fcd04

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Proxmox/Proxmox.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,30 @@ public function livestats()
4040
{
4141
$status = "active";
4242

43+
// Default data for inactive status (view template requires these variables)
44+
$inactiveData = [
45+
"vm_running" => 0,
46+
"vm_total" => 0,
47+
"container_running" => 0,
48+
"container_total" => 0,
49+
"cpu_percent" => 0,
50+
"memory_percent" => 0,
51+
];
52+
4353
$nodes = explode(",", $this->getConfigValue("nodes", ""));
4454

4555
if ($nodes == [""]) {
4656
$nodeData = $this->apiCall("nodes");
4757
if ($nodeData === null) {
48-
return parent::getLiveStats("inactive", []);
58+
return parent::getLiveStats("inactive", $inactiveData);
4959
}
5060
$nodes = array_map(function ($v) {
5161
return $v->node;
5262
}, $nodeData);
5363
}
5464

5565
if (empty($nodes)) {
56-
return parent::getLiveStats("inactive", []);
66+
return parent::getLiveStats("inactive", $inactiveData);
5767
}
5868

5969
$vm_running = 0;
@@ -96,7 +106,7 @@ public function livestats()
96106
}
97107

98108
if ($valid_nodes === 0) {
99-
return parent::getLiveStats("inactive", []);
109+
return parent::getLiveStats("inactive", $inactiveData);
100110
}
101111

102112
$data = [

0 commit comments

Comments
 (0)