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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
add VerifyIntent rollup substrate
rcourtmanbd62b6d8ad13
diff --git a/internal/recovery/model/types.go b/internal/recovery/model/types.goindex 603c74645a..80ac6c8c9e 100644--- a/internal/recovery/model/types.go+++ b/internal/recovery/model/types.go@@ -103,6 +103,22 @@ type RecoveryPointDisplay struct {DetailsSummary string `json:"detailsSummary,omitempty"`}+// VerifyIntent is a tri-state summary of whether a rollup's most recent+// successful backup has been verified within the configured staleness window.+type VerifyIntent string++const (+ // VerifyIntentVerified means a verification-bearing successful recovery+ // point exists within the staleness window.+ VerifyIntentVerified VerifyIntent = "verified"+ // VerifyIntentStale means a successful backup exists for the subject but+ // no verification-bearing point has landed within the staleness window.+ VerifyIntentStale VerifyIntent = "stale"+ // VerifyIntentUnknown means there is no information one way or the other+ // (no successful backup, or no verification-bearing points at all).+ VerifyIntentUnknown VerifyIntent = "unknown"+)+// ProtectionRollup is a per-resource summary derived from recovery points.type ProtectionRollup struct {// RollupID is a stable identifier used for drill-down into points.@@ -125,6 +141,16 @@ type ProtectionRollup struct {// Providers that contributed points within the query window.Providers []Provider `json:"providers,omitempty"`++ // VerifyIntent summarises whether the most recent successful backup for+ // this subject has been verified within the staleness window. Emitted+ // omitempty so existing rollup payload snapshots stay stable for callers+ // that have not opted into the read-side verify loop.+ VerifyIntent VerifyIntent `json:"verifyIntent,omitempty"`+ // LastVerifiedAt is the completion timestamp of the newest+ // verification-bearing recovery point on the rollup window. Nil when no+ // verified point exists in the window.+ LastVerifiedAt *time.Time `json:"lastVerifiedAt,omitempty"`}type ListPointsOptions struct {diff --git a/internal/recovery/recovery_test.go b/internal/recovery/recovery_test.goindex f172bd279e..78a3bd7a68 100644--- a/internal/recovery/recovery_test.go+++ b/internal/recovery/recovery_test.go@@ -1093,3 +1093,150 @@ func TestBuildRollupsFromPoints_PreservesLatestDisplayLabels(t *testing.T) {t.Fatal("expected rollup display workload marker to be preserved")}}++func TestBuildRollupsFromPoints_VerifyIntent(t *testing.T) {+ now := time.Date(2026, 5, 12, 12, 0, 0, 0, time.UTC)+ verified := true+ unverified := false++ insideWindow := now.Add(-2 * 24 * time.Hour)+ outsideWindow := now.Add(-21 * 24 * time.Hour)++ cases := []struct {+ name string+ points []RecoveryPoint+ wantIntent VerifyIntent+ wantVerifiedAt *time.Time+ }{+ {+ name: "verified within window",+ points: []RecoveryPoint{+ {+ ID: "p1",+ Provider: ProviderProxmoxPBS,+ Kind: KindBackup,+ Mode: ModeRemote,+ Outcome: OutcomeSuccess,+ StartedAt: &insideWindow,+ CompletedAt: &insideWindow,+ Verified: &verified,+ SubjectResourceID: "vm-100",+ },+ },+ wantIntent: VerifyIntentVerified,+ wantVerifiedAt: &insideWindow,+ },+ {+ name: "successful backup but verification outside window is stale",+ points: []RecoveryPoint{+ {+ ID: "p-recent",+ Provider: ProviderProxmoxPBS,+ Kind: KindBackup,+ Mode: ModeRemote,+ Outcome: OutcomeSuccess,+ StartedAt: &insideWindow,+ CompletedAt: &insideWindow,+ Verified: &unverified,+ SubjectResourceID: "vm-200",+ },+ {+ ID: "p-old-verified",+ Provider: ProviderProxmoxPBS,+ Kind: KindBackup,+ Mode: ModeRemote,+ Outcome: OutcomeSuccess,+ StartedAt: &outsideWindow,+ CompletedAt: &outsideWindow,+ Verified: &verified,+ SubjectResourceID: "vm-200",+ },+ },+ wantIntent: VerifyIntentStale,+ wantVerifiedAt: &outsideWindow,+ },+ {+ name: "successful backup with no verification anywhere is stale",+ points: []RecoveryPoint{+ {+ ID: "p-fresh-unverified",+ Provider: ProviderProxmoxPBS,+ Kind: KindBackup,+ Mode: ModeRemote,+ Outcome: OutcomeSuccess,+ StartedAt: &insideWindow,+ CompletedAt: &insideWindow,+ Verified: &unverified,+ SubjectResourceID: "vm-300",+ },+ },+ wantIntent: VerifyIntentStale,+ wantVerifiedAt: nil,+ },+ {+ name: "no successful backup is unknown",+ points: []RecoveryPoint{+ {+ ID: "p-fail",+ Provider: ProviderProxmoxPBS,+ Kind: KindBackup,+ Mode: ModeRemote,+ Outcome: OutcomeFailed,+ StartedAt: &insideWindow,+ CompletedAt: &insideWindow,+ SubjectResourceID: "vm-400",+ },+ },+ wantIntent: VerifyIntentUnknown,+ wantVerifiedAt: nil,+ },+ }++ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ rollups := BuildRollupsFromPointsAt(tc.points, now)+ if len(rollups) != 1 {+ t.Fatalf("expected 1 rollup, got %d", len(rollups))+ }+ got := rollups[0]+ if got.VerifyIntent != tc.wantIntent {+ t.Fatalf("VerifyIntent = %q, want %q", got.VerifyIntent, tc.wantIntent)+ }+ if tc.wantVerifiedAt == nil {+ if got.LastVerifiedAt != nil {+ t.Fatalf("LastVerifiedAt = %v, want nil", got.LastVerifiedAt)+ }+ } else {+ if got.LastVerifiedAt == nil {+ t.Fatalf("LastVerifiedAt = nil, want %v", tc.wantVerifiedAt)+ }+ if !got.LastVerifiedAt.Equal(*tc.wantVerifiedAt) {+ t.Fatalf("LastVerifiedAt = %v, want %v", got.LastVerifiedAt, tc.wantVerifiedAt)+ }+ }+ })+ }+}++func TestComputeVerifyIntentAt_BoundaryEqualsWindow(t *testing.T) {+ now := time.Date(2026, 5, 12, 12, 0, 0, 0, time.UTC)+ // Exactly at the window boundary should still be verified (inclusive).+ verifiedAt := now.Add(-BackupVerifyStaleWindow)+ intent, ts := ComputeVerifyIntentAt(verifiedAt.UnixMilli(), verifiedAt.UnixMilli(), now)+ if intent != VerifyIntentVerified {+ t.Fatalf("boundary intent = %q, want %q", intent, VerifyIntentVerified)+ }+ if ts == nil || !ts.Equal(verifiedAt) {+ t.Fatalf("boundary lastVerifiedAt = %v, want %v", ts, verifiedAt)+ }++ // One millisecond beyond the window flips to stale.+ beyond := verifiedAt.Add(-time.Millisecond)+ intent, ts = ComputeVerifyIntentAt(beyond.UnixMilli(), beyond.UnixMilli(), now)+ if intent != VerifyIntentStale {+ t.Fatalf("beyond boundary intent = %q, want %q", intent, VerifyIntentStale)+ }+ if ts == nil {+ t.Fatalf("beyond boundary lastVerifiedAt = nil, want non-nil so UI can render history")+ }+}diff --git a/internal/recovery/rollups.go b/internal/recovery/rollups.goindex 75b68442c6..e1ee167898 100644--- a/internal/recovery/rollups.go+++ b/internal/recovery/rollups.go@@ -6,6 +6,46 @@ import ("time")+// BackupVerifyStaleWindow is the default lookback used to decide whether a+// successful backup has been verified recently enough. A successful backup+// without a verification-bearing point inside this window flips the rollup's+// VerifyIntent to stale. MVP keeps this as a package-level constant; a+// future configurable plumbing change will replace it.+const BackupVerifyStaleWindow = 7 * 24 * time.Hour++// ComputeVerifyIntentAt returns the verify intent and the newest verified+// timestamp for a subject, given the most recent successful attempt and the+// newest verification-bearing point seen on the rollup. The "now" parameter+// is injected so tests and the SQL rollup path stay deterministic.+//+// Semantics:+// - verified : a verification-bearing point exists within window of now+// - stale : a successful backup exists, but no verification within window+// - unknown : no successful backup at all (or no info)+//+// LastVerifiedAt is returned regardless of intent (when known) so consumers+// can surface "last verified X days ago" alongside the badge.+func ComputeVerifyIntentAt(lastSuccessMs, lastVerifiedMs int64, now time.Time) (VerifyIntent, *time.Time) {+ windowMs := BackupVerifyStaleWindow.Milliseconds()+ nowMs := now.UTC().UnixMilli()++ var lastVerifiedAt *time.Time+ if lastVerifiedMs > 0 {+ t := time.UnixMilli(lastVerifiedMs).UTC()+ lastVerifiedAt = &t+ }++ if lastSuccessMs <= 0 {+ return VerifyIntentUnknown, lastVerifiedAt+ }++ if lastVerifiedMs > 0 && nowMs-lastVerifiedMs <= windowMs {+ return VerifyIntentVerified, lastVerifiedAt+ }++ return VerifyIntentStale, lastVerifiedAt+}+func displayForRollupPoint(p RecoveryPoint) *RecoveryPointDisplay {if p.Display != nil {display := *p.Display@@ -18,6 +58,12 @@ func displayForRollupPoint(p RecoveryPoint) *RecoveryPointDisplay {// This mirrors the sqlite rollup semantics (timestamp selection + success window)// so mock mode and in-memory consumers behave consistently with persisted stores.func BuildRollupsFromPoints(points []RecoveryPoint) []ProtectionRollup {+ return BuildRollupsFromPointsAt(points, time.Now())+}++// BuildRollupsFromPointsAt is the now-injectable companion used by tests so+// VerifyIntent staleness is deterministic regardless of wall-clock drift.+func BuildRollupsFromPointsAt(points []RecoveryPoint, now time.Time) []ProtectionRollup {if len(points) == 0 {return []ProtectionRollup{}}@@ -30,8 +76,9 @@ func BuildRollupsFromPoints(points []RecoveryPoint) []ProtectionRollup {latestID stringlatestOutcome Outcome- lastAttemptMs int64- lastSuccessMs int64+ lastAttemptMs int64+ lastSuccessMs int64+ lastVerifiedMs int64// Latest identity seen (ties resolved by latestTS/updated/id).subjectRID string@@ -113,6 +160,11 @@ func BuildRollupsFromPoints(points []RecoveryPoint) []ProtectionRollup {if p.Outcome == OutcomeSuccess && tsMs > a.lastSuccessMs {a.lastSuccessMs = tsMs}+ // Track the newest verification-bearing point on the rollup window so+ // the VerifyIntent computation downstream can grade the subject.+ if p.Verified != nil && *p.Verified && tsMs > a.lastVerifiedMs {+ a.lastVerifiedMs = tsMs+ }// Latest-point identity + outcome: choose the point with the greatest ts,// then updated, then id lexicographically.@@ -155,6 +207,8 @@ func BuildRollupsFromPoints(points []RecoveryPoint) []ProtectionRollup {}sort.Slice(providers, func(i, j int) bool { return string(providers[i]) < string(providers[j]) })+ verifyIntent, lastVerifiedAt := ComputeVerifyIntentAt(a.lastSuccessMs, a.lastVerifiedMs, now)+out = append(out, ProtectionRollup{RollupID: strings.TrimSpace(a.subjectKey),SubjectResourceID: a.subjectRID,@@ -164,6 +218,8 @@ func BuildRollupsFromPoints(points []RecoveryPoint) []ProtectionRollup {LastSuccessAt: lastSuccessAt,LastOutcome: a.latestOutcome,Providers: providers,+ VerifyIntent: verifyIntent,+ LastVerifiedAt: lastVerifiedAt,})}diff --git a/internal/recovery/store/store.go b/internal/recovery/store/store.goindex d12de6b408..5196ff1437 100644--- a/internal/recovery/store/store.go+++ b/internal/recovery/store/store.go@@ -1629,6 +1629,7 @@ func (s *Store) ListRollups(ctx context.Context, opts recovery.ListPointsOptionsdetails_summary,provider,outcome,+ verified,` + tsExpr + ` AS ts_ms,updated_at_ms,id@@ -1639,7 +1640,8 @@ func (s *Store) ListRollups(ctx context.Context, opts recovery.ListPointsOptionsSELECTsubject_key,MAX(ts_ms) AS last_attempt_ms,- MAX(CASE WHEN outcome = 'success' THEN ts_ms END) AS last_success_ms+ MAX(CASE WHEN outcome = 'success' THEN ts_ms END) AS last_success_ms,+ MAX(CASE WHEN verified = 1 THEN ts_ms END) AS last_verified_msFROM filteredGROUP BY subject_key),@@ -1706,6 +1708,7 @@ func (s *Store) ListRollups(ctx context.Context, opts recovery.ListPointsOptionslatest.details_summary,agg.last_attempt_ms,agg.last_success_ms,+ agg.last_verified_ms,(SELECT outcome FROM ranked r WHERE r.subject_key = agg.subject_key AND r.rn = 1) AS last_outcome,providers.providers_csvFROM agg@@ -1739,6 +1742,7 @@ func (s *Store) ListRollups(ctx context.Context, opts recovery.ListPointsOptionsvar detailsSummary sql.NullStringvar lastAttemptMs sql.NullInt64var lastSuccessMs sql.NullInt64+ var lastVerifiedMs sql.NullInt64var lastOutcome stringvar providersRaw sql.NullString@@ -1758,6 +1762,7 @@ func (s *Store) ListRollups(ctx context.Context, opts recovery.ListPointsOptions&detailsSummary,&lastAttemptMs,&lastSuccessMs,+ &lastVerifiedMs,&lastOutcome,&providersRaw,); err != nil {@@ -1774,6 +1779,17 @@ func (s *Store) ListRollups(ctx context.Context, opts recovery.ListPointsOptionst := time.UnixMilli(lastSuccessMs.Int64).UTC()lastSuccessAt = &t}+ var lastSuccessMsValue int64+ if lastSuccessMs.Valid {+ lastSuccessMsValue = lastSuccessMs.Int64+ }+ var lastVerifiedMsValue int64+ if lastVerifiedMs.Valid {+ lastVerifiedMsValue = lastVerifiedMs.Int64+ }+ verifyIntent, lastVerifiedAt := recovery.ComputeVerifyIntentAt(+ lastSuccessMsValue, lastVerifiedMsValue, time.Now(),+ )var subjectRef recovery.ExternalRef_ = decodeRecoveryJSONField(subjectKey, "subject_ref_json", subjectRefRaw, &subjectRef)@@ -1820,6 +1836,8 @@ func (s *Store) ListRollups(ctx context.Context, opts recovery.ListPointsOptionsLastSuccessAt: lastSuccessAt,LastOutcome: outcome,Providers: providers,+ VerifyIntent: verifyIntent,+ LastVerifiedAt: lastVerifiedAt,})}if err := rows.Err(); err != nil {diff --git a/internal/recovery/store/store_rollups_test.go b/internal/recovery/store/store_rollups_test.goindex 4b08e38305..e43af56598 100644--- a/internal/recovery/store/store_rollups_test.go+++ b/internal/recovery/store/store_rollups_test.go@@ -228,6 +228,115 @@ func TestStore_ListRollups(t *testing.T) {}}+func TestStore_ListRollups_VerifyIntent(t *testing.T) {+ t.Parallel()++ dir := t.TempDir()+ dbPath := filepath.Join(dir, "recovery.db")++ store, err := Open(dbPath)+ if err != nil {+ t.Fatalf("Open() error = %v", err)+ }+ t.Cleanup(func() { _ = store.Close() })++ // Truncate to millisecond precision: the persistence layer stores+ // completion timestamps as int64 milliseconds, so any sub-millisecond+ // precision in time.Now() would not round-trip and would fail the+ // reflective Equal() assertion below.+ now := time.Now().UTC().Truncate(time.Millisecond)+ recent := now.Add(-2 * 24 * time.Hour)+ old := now.Add(-21 * 24 * time.Hour)++ verified := true+ unverified := false++ points := []recovery.RecoveryPoint{+ {+ ID: "verified-fresh",+ Provider: recovery.ProviderProxmoxPBS,+ Kind: recovery.KindBackup,+ Mode: recovery.ModeRemote,+ Outcome: recovery.OutcomeSuccess,+ StartedAt: &recent,+ CompletedAt: &recent,+ Verified: &verified,+ SubjectResourceID: "vm-verified",+ },+ {+ ID: "stale-fresh-success",+ Provider: recovery.ProviderProxmoxPBS,+ Kind: recovery.KindBackup,+ Mode: recovery.ModeRemote,+ Outcome: recovery.OutcomeSuccess,+ StartedAt: &recent,+ CompletedAt: &recent,+ Verified: &unverified,+ SubjectResourceID: "vm-stale",+ },+ {+ ID: "stale-old-verification",+ Provider: recovery.ProviderProxmoxPBS,+ Kind: recovery.KindBackup,+ Mode: recovery.ModeRemote,+ Outcome: recovery.OutcomeSuccess,+ StartedAt: &old,+ CompletedAt: &old,+ Verified: &verified,+ SubjectResourceID: "vm-stale",+ },+ {+ ID: "unknown-failed-only",+ Provider: recovery.ProviderProxmoxPBS,+ Kind: recovery.KindBackup,+ Mode: recovery.ModeRemote,+ Outcome: recovery.OutcomeFailed,+ StartedAt: &recent,+ CompletedAt: &recent,+ SubjectResourceID: "vm-unknown",+ },+ }++ if err := store.UpsertPoints(context.Background(), points); err != nil {+ t.Fatalf("UpsertPoints() error = %v", err)+ }++ got, _, err := store.ListRollups(context.Background(), recovery.ListPointsOptions{Page: 1, Limit: 50})+ if err != nil {+ t.Fatalf("ListRollups() error = %v", err)+ }++ intentByRollup := make(map[string]recovery.VerifyIntent, len(got))+ verifiedAtByRollup := make(map[string]*time.Time, len(got))+ for _, r := range got {+ intentByRollup[r.RollupID] = r.VerifyIntent+ verifiedAtByRollup[r.RollupID] = r.LastVerifiedAt+ }++ if intentByRollup["res:vm-verified"] != recovery.VerifyIntentVerified {+ t.Fatalf("vm-verified intent = %q, want %q",+ intentByRollup["res:vm-verified"], recovery.VerifyIntentVerified)+ }+ if intentByRollup["res:vm-stale"] != recovery.VerifyIntentStale {+ t.Fatalf("vm-stale intent = %q, want %q",+ intentByRollup["res:vm-stale"], recovery.VerifyIntentStale)+ }+ if intentByRollup["res:vm-unknown"] != recovery.VerifyIntentUnknown {+ t.Fatalf("vm-unknown intent = %q, want %q",+ intentByRollup["res:vm-unknown"], recovery.VerifyIntentUnknown)+ }++ if got := verifiedAtByRollup["res:vm-verified"]; got == nil || !got.Equal(recent) {+ t.Fatalf("vm-verified lastVerifiedAt = %v, want %v", got, recent)+ }+ if got := verifiedAtByRollup["res:vm-stale"]; got == nil || !got.Equal(old) {+ t.Fatalf("vm-stale lastVerifiedAt = %v, want historical %v", got, old)+ }+ if got := verifiedAtByRollup["res:vm-unknown"]; got != nil {+ t.Fatalf("vm-unknown lastVerifiedAt = %v, want nil", got)+ }+}+func TestStore_ListRollups_IgnoresMalformedSubjectRefJSON(t *testing.T) {t.Parallel()diff --git a/internal/recovery/types.go b/internal/recovery/types.goindex 76030e6671..0f8f46fa03 100644--- a/internal/recovery/types.go+++ b/internal/recovery/types.go@@ -52,3 +52,11 @@ type ProtectionRollup = model.ProtectionRolluptype ListPointsOptions = model.ListPointsOptionstype PointsSeriesBucket = model.PointsSeriesBuckettype PointsFacets = model.PointsFacets++type VerifyIntent = model.VerifyIntent++const (+ VerifyIntentVerified VerifyIntent = model.VerifyIntentVerified+ VerifyIntentStale VerifyIntent = model.VerifyIntentStale+ VerifyIntentUnknown VerifyIntent = model.VerifyIntentUnknown+)