Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Treat empty pct list output as an empty LXC inventory

rcourtman2dc0420e84da
diff --git a/internal/hostagent/privilege_helper_client_test.go b/internal/hostagent/privilege_helper_client_test.go
index 97b4cb7367..e52f13e17f 100644
--- a/internal/hostagent/privilege_helper_client_test.go
+++ b/internal/hostagent/privilege_helper_client_test.go
@@ -533,7 +533,10 @@ func TestCollectProxmoxInvalidListCannotBecomeCompleteEmpty(t *testing.T) {
}{
{"header only", header, true},
{"all stopped", header + "100 stopped - web\n", true},
- {"empty output", "", false},
+ // pct list prints nothing, not even the header, on a node with no
+ // containers (pve-container src/PVE/CLI/pct.pm returns before the
+ // header printf), so empty output is the vendor's empty inventory.
+ {"empty output", "", true},
{"unrecognised output", "pmxcfs unavailable\n", false},
{"headerless rows", "100 running - web\n", false},
{"malformed header", "VMID Status\n", false},
diff --git a/internal/hostagent/proxmox_lxc_filesystems.go b/internal/hostagent/proxmox_lxc_filesystems.go
index 89e46794dd..b1e5ce4260 100644
--- a/internal/hostagent/proxmox_lxc_filesystems.go
+++ b/internal/hostagent/proxmox_lxc_filesystems.go
@@ -514,9 +514,12 @@ func parseProxmoxLXCRunningContainers(output string) ([]proxmoxLXCRunningContain
}
result = append(result, proxmoxLXCRunningContainer{VMID: vmid, Name: name})
}
- if !sawHeader {
- return nil, errors.New("pct list has no inventory header")
- }
+ // pct list prints nothing at all, not even the header, when the node has
+ // no containers (pve-container src/PVE/CLI/pct.pm returns before the
+ // header printf on an empty vmlist). Reaching here without a header means
+ // every line was blank: any non-blank line before the header is already
+ // rejected above, so this is a complete, empty inventory rather than
+ // truncated output.
sort.Slice(result, func(i, j int) bool { return result[i].VMID < result[j].VMID })
return result, nil
}
diff --git a/internal/hostagent/proxmox_lxc_filesystems_test.go b/internal/hostagent/proxmox_lxc_filesystems_test.go
index 77d7d0cced..d856ab7fdf 100644
--- a/internal/hostagent/proxmox_lxc_filesystems_test.go
+++ b/internal/hostagent/proxmox_lxc_filesystems_test.go
@@ -441,6 +441,78 @@ func TestParseProxmoxLXCFilesystemsValidatesAndBoundsInput(t *testing.T) {
); err == nil {
t.Fatal("expected oversized pct list error")
}
+}
+
+// pct list prints nothing, not even its header, on a node with no containers
+// (pve-container src/PVE/CLI/pct.pm). Blank output is a complete empty
+// inventory; any non-blank line still needs the header first.
+func TestParseProxmoxLXCRunningContainersEmptyNode(t *testing.T) {
+ for name, output := range map[string]string{
+ "empty": "",
+ "whitespace only": " \n\t\r\n\n",
+ } {
+ containers, err := parseProxmoxLXCRunningContainers(output)
+ if err != nil || containers == nil || len(containers) != 0 {
+ t.Fatalf("%s: containers=%+v err=%v, want empty inventory", name, containers, err)
+ }
+ }
+ for name, output := range map[string]string{
+ "row without header": "100 running - web\n",
+ "garbage": "pct: unexpected\n",
+ "header after a row": "100 running - web\nVMID Status Lock Name\n",
+ "truncated header": "VMID Status\n",
+ "leading blank + row": "\n\n100 running - web\n",
+ } {
+ if containers, err := parseProxmoxLXCRunningContainers(output); err == nil || containers != nil {
+ t.Fatalf("%s: containers=%+v err=%v, want error", name, containers, err)
+ }
+ }
+ containers, err := parseProxmoxLXCRunningContainers("VMID Status Lock Name\n")
+ if err != nil || len(containers) != 0 {
+ t.Fatalf("header only: containers=%+v err=%v", containers, err)
+ }
+ containers, err = parseProxmoxLXCRunningContainers(
+ "VMID Status Lock Name \n" +
+ "101 stopped archive \n" +
+ "100 running web \n",
+ )
+ if err != nil || len(containers) != 1 || containers[0].VMID != 100 || containers[0].Name != "web" {
+ t.Fatalf("normal list: containers=%+v err=%v", containers, err)
+ }
+}
+
+func TestCollectProxmoxLXCFilesystemsEmptyNodeIsComplete(t *testing.T) {
+ const pctPath = "/usr/sbin/pct"
+ var commands []string
+ collector := &mockCollector{
+ goos: "linux",
+ lookPathFn: func(file string) (string, error) {
+ if file == "pct" {
+ return pctPath, nil
+ }
+ return "", os.ErrNotExist
+ },
+ commandCombinedOutputLimitedFn: func(_ context.Context, _ int, _ string, args ...string) (string, error) {
+ commands = append(commands, strings.Join(args, " "))
+ if strings.Join(args, " ") == "list" {
+ return "", nil
+ }
+ return "", errors.New("unexpected pct query")
+ },
+ }
+
+ result := (&Agent{logger: zerolog.Nop(), collector: collector}).collectProxmoxLXCFilesystemsResult(t.Context())
+ if !result.Applicable || result.Degraded || result.FailedContainers != 0 {
+ t.Fatalf("collection result = %+v, want applicable complete empty collection", result)
+ }
+ if result.Inventory == nil || len(result.Inventory.Containers) != 0 ||
+ result.Inventory.Status != "complete" || len(result.Inventory.OmittedVMIDs) != 0 ||
+ result.Inventory.ValidateCollection() != nil {
+ t.Fatalf("inventory = %+v, want complete empty inventory", result.Inventory)
+ }
+ if len(commands) != 1 || commands[0] != "list" {
+ t.Fatalf("commands = %v, want only pct list", commands)
+ }
disks, err := parseProxmoxLXCDF(`MP Volume Size Used Avail Use% Path
mp1 pool:valid 10.0G 4.0G 6.0G 40.0 /valid