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.

fix(pbs): reject incomplete alerting measurements

pulse-triage[bot]3d984b0226fd
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index a5db628522..e4ca250825 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -21,14 +21,26 @@ PBS node-status collection must reject HTTP-success responses whose `data`
is omitted or null (including a null response envelope). Absent status is
unavailable telemetry, not measured zero usage: the poller retains independently
established connectivity, marks node metrics unavailable, and must not resolve
-an active metric incident from that response. This does not add per-field
-validation of populated status objects.
+an active metric incident from that response. Populated objects must include
+non-null CPU, memory used and memory total measurements, with non-negative
+usage and a positive memory denominator. Missing fields must not become zero
+usage. Since the poller has a single node-metrics availability flag, incomplete
+CPU or memory makes the node metrics unavailable together; unrelated status
+fields are not required. Explicit zero CPU and memory usage remain valid.
+
+The upstream PBS API schema at
+https://pbs.proxmox.com/docs/api-viewer/apidoc.js (read 2026-09-05) declares CPU
+and memory used/total as numeric measurements. This validation is limited to
+measurements consumed by node alerting, not exhaustive schema enforcement.
Verification: `TestClient_GetNodeStatus_MissingData` in
`pkg/pbs/client_http_test.go` covers the absent envelopes.
`TestPBSPartialMetricsWebhookLifecycle` in
`internal/monitoring/monitor_pbs_webhook_test.go` exercises repeated null status
-through the real poller, alert manager, notification queue and local webhook.
+and missing memory-used measurements through the real poller, alert manager,
+notification queue and local webhook. `TestClient_GetNodeStatus_MetricCompleteness`
+pins omitted/null fields, invalid denominators, negative usage, genuine zero,
+and tolerance for unrelated extra fields.
It requires online-but-unavailable projection, unchanged incident identity,
no false recovery history or delivery, then one identity-preserving recovery
after valid low-memory samples. These are local synthetic checks, not
diff --git a/internal/monitoring/monitor_pbs_health_authority_test.go b/internal/monitoring/monitor_pbs_health_authority_test.go
index 117be78f4e..3ff3e99244 100644
--- a/internal/monitoring/monitor_pbs_health_authority_test.go
+++ b/internal/monitoring/monitor_pbs_health_authority_test.go
@@ -27,6 +27,7 @@ const (
pbsHealthTestUnavailable
pbsHealthTestLowMemory
pbsHealthTestNullNodeStatus
+ pbsHealthTestIncompleteNodeStatus
)
type pbsHealthTestServer struct {
@@ -67,6 +68,10 @@ func newPBSHealthTestServer(t *testing.T) *pbsHealthTestServer {
"data": map[string]any{"version": "3.4.2"},
})
case "/api2/json/nodes/localhost/status":
+ if mode == pbsHealthTestIncompleteNodeStatus {
+ _, _ = w.Write([]byte(`{"data":{"cpu":0.15,"memory":{"total":1024}}}`))
+ return
+ }
if mode == pbsHealthTestNullNodeStatus {
_, _ = w.Write([]byte(`{"data":null}`))
return
diff --git a/internal/monitoring/monitor_pbs_webhook_test.go b/internal/monitoring/monitor_pbs_webhook_test.go
index 098ae51a8e..19ebe7c198 100644
--- a/internal/monitoring/monitor_pbs_webhook_test.go
+++ b/internal/monitoring/monitor_pbs_webhook_test.go
@@ -98,7 +98,7 @@ func TestPBSPartialMetricsWebhookLifecycle(t *testing.T) {
}
incident := firing.Alerts[0]
waitSent(1)
- for _, mode := range []pbsHealthTestMode{pbsHealthTestNodeDenied, pbsHealthTestNodeGatewayFailure, pbsHealthTestNullNodeStatus} {
+ for _, mode := range []pbsHealthTestMode{pbsHealthTestNodeDenied, pbsHealthTestNodeGatewayFailure, pbsHealthTestNullNodeStatus, pbsHealthTestIncompleteNodeStatus} {
fixture.setMode(mode)
for range 5 {
poll()
diff --git a/pkg/pbs/client.go b/pkg/pbs/client.go
index ef9aba61ea..ed1553e243 100644
--- a/pkg/pbs/client.go
+++ b/pkg/pbs/client.go
@@ -784,6 +784,30 @@ func (c *Client) GetNodeStatus(ctx context.Context) (*NodeStatus, error) {
return nil, fmt.Errorf("node status response contains no data")
}
+ // The poller has one availability flag for CPU and memory. Require both
+ // measurements before marking the snapshot available; omitted JSON numbers
+ // otherwise decode to zero and can fabricate recovery. Do not require
+ // unrelated fields (load, swap, root, etc.) or reject measured zero usage.
+ var measurements struct {
+ Data struct {
+ CPU *float64 `json:"cpu"`
+ Memory struct {
+ Used *int64 `json:"used"`
+ Total *int64 `json:"total"`
+ } `json:"memory"`
+ } `json:"data"`
+ }
+ if err := json.Unmarshal(body, &measurements); err != nil {
+ return nil, fmt.Errorf("failed to decode node measurements: %w", err)
+ }
+ m := measurements.Data
+ if m.CPU == nil || m.Memory.Used == nil || m.Memory.Total == nil {
+ return nil, fmt.Errorf("node status response contains incomplete CPU or memory measurements")
+ }
+ if *m.CPU < 0 || *m.Memory.Used < 0 || *m.Memory.Total <= 0 {
+ return nil, fmt.Errorf("node status response contains invalid CPU or memory measurements")
+ }
+
return statusResult.Data, nil
}
diff --git a/pkg/pbs/client_http_test.go b/pkg/pbs/client_http_test.go
index 04b5efce81..dcf4665d74 100644
--- a/pkg/pbs/client_http_test.go
+++ b/pkg/pbs/client_http_test.go
@@ -836,7 +836,7 @@ func TestClient_GetNodeStatus_PermissionOutageRecovery(t *testing.T) {
_, _ = w.Write([]byte("permission denied: upstream authentication error"))
return
}
- _, _ = w.Write([]byte(`{"data":{"cpu":0.25}}`))
+ _, _ = w.Write([]byte(`{"data":{"cpu":0.25,"memory":{"used":500,"total":1000}}}`))
}))
defer server.Close()
client, err := NewClient(ClientConfig{
@@ -885,3 +885,43 @@ func TestClient_GetNodeStatus_MissingData(t *testing.T) {
})
}
}
+
+// Missing measurements must not be indistinguishable from measured zero usage.
+func TestClient_GetNodeStatus_MetricCompleteness(t *testing.T) {
+ for _, tc := range []struct {
+ name, data string
+ valid bool
+ }{
+ {"empty", `{}`, false},
+ {"cpu only", `{"cpu":0}`, false},
+ {"missing cpu", `{"memory":{"used":0,"total":1000}}`, false},
+ {"null cpu", `{"cpu":null,"memory":{"used":0,"total":1000}}`, false},
+ {"null memory", `{"cpu":0,"memory":null}`, false},
+ {"missing used", `{"cpu":0,"memory":{"total":1000}}`, false},
+ {"null used", `{"cpu":0,"memory":{"used":null,"total":1000}}`, false},
+ {"missing total", `{"cpu":0,"memory":{"used":0}}`, false},
+ {"null total", `{"cpu":0,"memory":{"used":0,"total":null}}`, false},
+ {"zero total", `{"cpu":0,"memory":{"used":0,"total":0}}`, false},
+ {"negative total", `{"cpu":0,"memory":{"used":0,"total":-1}}`, false},
+ {"negative used", `{"cpu":0,"memory":{"used":-1,"total":1000}}`, false},
+ {"negative cpu", `{"cpu":-1,"memory":{"used":0,"total":1000}}`, false},
+ {"wrong type", `{"cpu":0,"memory":{"used":"0","total":1000}}`, false},
+ {"measured zero", `{"cpu":0,"memory":{"used":0,"total":1000}}`, true},
+ {"extra fields", `{"cpu":0.2,"memory":{"used":500,"total":1000,"free":500},"future":true}`, true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ client, server := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
+ _, _ = w.Write([]byte(`{"data":` + tc.data + `}`))
+ })
+ defer server.Close()
+ status, err := client.GetNodeStatus(context.Background())
+ if tc.valid {
+ if err != nil || status == nil {
+ t.Fatalf("valid measurements = (%+v, %v)", status, err)
+ }
+ } else if err == nil || status != nil {
+ t.Fatalf("incomplete/invalid measurements = (%+v, %v), want nil status and error", status, err)
+ }
+ })
+ }
+}