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
Wire platform poller state into connections ledger
rcourtmanb6af1d233ecc
diff --git a/internal/api/connections_aggregator.go b/internal/api/connections_aggregator.goindex 6793ff880e..e384a3850e 100644--- a/internal/api/connections_aggregator.go+++ b/internal/api/connections_aggregator.go@@ -91,7 +91,9 @@ type aggregatorInputs struct {pbsInstances []config.PBSInstancepmgInstances []config.PMGInstancevmwareInstances []config.VMwareVCenterInstance+ vmwareSummaries map[string]monitoring.VMwareConnectionSummarytruenasInstances []config.TrueNASInstance+ truenasSummaries map[string]monitoring.TrueNASConnectionSummaryavailabilityTargets []config.AvailabilityTargetavailabilityStatuses map[string]monitoring.AvailabilityProbeStatushosts []models.Host@@ -129,10 +131,10 @@ func buildConnections(in aggregatorInputs) []Connection {out = append(out, buildPMGConnection(pmg, in.instanceHealth, now))}for _, vmw := range in.vmwareInstances {- out = append(out, buildVMwareConnection(vmw, in.instanceHealth, now))+ out = append(out, buildVMwareConnection(vmw, in.instanceHealth, in.vmwareSummaries, now))}for _, tn := range in.truenasInstances {- out = append(out, buildTrueNASConnection(tn, in.instanceHealth, now))+ out = append(out, buildTrueNASConnection(tn, in.instanceHealth, in.truenasSummaries, now))}for _, target := range in.availabilityTargets {out = append(out, buildAvailabilityConnection(target, in.availabilityStatuses[target.ID], now))@@ -247,7 +249,12 @@ func buildPMGConnection(inst config.PMGInstance, health map[string]monitoring.Inreturn conn}-func buildVMwareConnection(inst config.VMwareVCenterInstance, health map[string]monitoring.InstanceHealth, now time.Time) Connection {+func buildVMwareConnection(+ inst config.VMwareVCenterInstance,+ health map[string]monitoring.InstanceHealth,+ summaries map[string]monitoring.VMwareConnectionSummary,+ now time.Time,+) Connection {enabled := inst.Enabledsurfaces := []string{"vms", "hosts", "datastores"}scope := map[string]bool{@@ -256,6 +263,9 @@ func buildVMwareConnection(inst config.VMwareVCenterInstance, health map[string]"datastores": inst.MonitorDatastores,}h := health["vmware::"+inst.ID]+ if summary, ok := summaries[strings.TrimSpace(inst.ID)]; ok {+ h = mergeVMwareSummaryHealth(h, summary)+ }state, reason, lastSeen, lastError := deriveConnectionState(enabled, h, now)port := inst.Portif port == 0 {@@ -281,7 +291,12 @@ func buildVMwareConnection(inst config.VMwareVCenterInstance, health map[string]return conn}-func buildTrueNASConnection(inst config.TrueNASInstance, health map[string]monitoring.InstanceHealth, now time.Time) Connection {+func buildTrueNASConnection(+ inst config.TrueNASInstance,+ health map[string]monitoring.InstanceHealth,+ summaries map[string]monitoring.TrueNASConnectionSummary,+ now time.Time,+) Connection {enabled := inst.Enabledsurfaces := []string{"datasets", "pools", "replication"}scope := map[string]bool{@@ -290,6 +305,9 @@ func buildTrueNASConnection(inst config.TrueNASInstance, health map[string]monit"replication": inst.MonitorReplication,}h := health["truenas::"+inst.ID]+ if summary, ok := summaries[strings.TrimSpace(inst.ID)]; ok {+ h = mergeTrueNASSummaryHealth(h, summary)+ }state, reason, lastSeen, lastError := deriveConnectionState(enabled, h, now)scheme := "https"if !inst.UseHTTPS {@@ -323,6 +341,113 @@ func buildTrueNASConnection(inst config.TrueNASInstance, health map[string]monitreturn conn}+func mergeVMwareSummaryHealth(+ h monitoring.InstanceHealth,+ summary monitoring.VMwareConnectionSummary,+) monitoring.InstanceHealth {+ if summary.Poll == nil {+ return h+ }+ return mergePlatformPollHealth(+ h,+ summary.Poll.LastSuccessAt,+ vmwarePollErrorAt(summary.Poll.LastError),+ vmwarePollErrorMessage(summary.Poll.LastError),+ vmwarePollErrorCategory(summary.Poll.LastError),+ summary.Poll.ConsecutiveFailures,+ )+}++func mergeTrueNASSummaryHealth(+ h monitoring.InstanceHealth,+ summary monitoring.TrueNASConnectionSummary,+) monitoring.InstanceHealth {+ if summary.Poll == nil {+ return h+ }+ return mergePlatformPollHealth(+ h,+ summary.Poll.LastSuccessAt,+ trueNASPollErrorAt(summary.Poll.LastError),+ trueNASPollErrorMessage(summary.Poll.LastError),+ trueNASPollErrorCategory(summary.Poll.LastError),+ summary.Poll.ConsecutiveFailures,+ )+}++func mergePlatformPollHealth(+ h monitoring.InstanceHealth,+ lastSuccess *time.Time,+ lastErrorAt *time.Time,+ lastErrorMessage string,+ lastErrorCategory string,+ consecutiveFailures int,+) monitoring.InstanceHealth {+ if lastSuccess != nil && !lastSuccess.IsZero() {+ t := *lastSuccess+ h.PollStatus.LastSuccess = &t+ }+ if consecutiveFailures > h.PollStatus.ConsecutiveFailures {+ h.PollStatus.ConsecutiveFailures = consecutiveFailures+ }++ lastErrorMessage = strings.TrimSpace(lastErrorMessage)+ if lastErrorMessage != "" {+ at := time.Time{}+ if lastErrorAt != nil {+ at = *lastErrorAt+ }+ h.PollStatus.LastError = &monitoring.ErrorDetail{+ At: at,+ Message: lastErrorMessage,+ Category: strings.TrimSpace(lastErrorCategory),+ }+ }+ return h+}++func vmwarePollErrorAt(err *monitoring.VMwareConnectionPollError) *time.Time {+ if err == nil {+ return nil+ }+ return err.At+}++func vmwarePollErrorMessage(err *monitoring.VMwareConnectionPollError) string {+ if err == nil {+ return ""+ }+ return err.Message+}++func vmwarePollErrorCategory(err *monitoring.VMwareConnectionPollError) string {+ if err == nil {+ return ""+ }+ return err.Category+}++func trueNASPollErrorAt(err *monitoring.TrueNASConnectionPollError) *time.Time {+ if err == nil {+ return nil+ }+ return err.At+}++func trueNASPollErrorMessage(err *monitoring.TrueNASConnectionPollError) string {+ if err == nil {+ return ""+ }+ return err.Message+}++func trueNASPollErrorCategory(err *monitoring.TrueNASConnectionPollError) string {+ if err == nil {+ return ""+ }+ return err.Category+}+func buildAvailabilityConnection(target config.AvailabilityTarget, status monitoring.AvailabilityProbeStatus, now time.Time) Connection {target = config.NormalizeAvailabilityTarget(target)state, reason, lastSeen, lastError := deriveAvailabilityConnectionState(target, status, now)@@ -1037,6 +1162,10 @@ func deriveConnectionState(enabled bool, h monitoring.InstanceHealth, now time.Treturn ConnectionStateUnauthorized, lastError.Message, lastSeen, lastError}+ if lastSeen == nil && lastError != nil {+ return ConnectionStateUnreachable, lastError.Message, lastSeen, lastError+ }+if strings.EqualFold(h.Breaker.State, "open") {reason := "circuit breaker open"if lastError != nil {diff --git a/internal/api/connections_aggregator_test.go b/internal/api/connections_aggregator_test.goindex 0b03834826..d236b80485 100644--- a/internal/api/connections_aggregator_test.go+++ b/internal/api/connections_aggregator_test.go@@ -839,6 +839,83 @@ func TestBuildConnections_VMwareAndTrueNASEnabledFlag(t *testing.T) {}}+func TestBuildConnections_PlatformPollerSummariesDriveRuntimeState(t *testing.T) {+ now := time.Now().UTC()+ vmwareSuccess := now.Add(-40 * time.Second)+ trueNASSuccess := now.Add(-30 * time.Second)+ in := aggregatorInputs{+ vmwareInstances: []config.VMwareVCenterInstance{{+ ID: "vc1", Name: "vc", Host: "vc.lan", Enabled: true,+ MonitorVMs: true, MonitorHosts: true, MonitorDatastores: true,+ }},+ vmwareSummaries: map[string]monitoring.VMwareConnectionSummary{+ "vc1": {+ Poll: &monitoring.VMwareConnectionPollStatus{+ LastSuccessAt: &vmwareSuccess,+ },+ },+ },+ truenasInstances: []config.TrueNASInstance{{+ ID: "tn1", Name: "tn", Host: "tn.lan", Enabled: true, UseHTTPS: true,+ APIKey: "secret", MonitorDatasets: true, MonitorPools: true, MonitorReplication: true,+ }},+ truenasSummaries: map[string]monitoring.TrueNASConnectionSummary{+ "tn1": {+ Poll: &monitoring.TrueNASConnectionPollStatus{+ LastSuccessAt: &trueNASSuccess,+ },+ },+ },+ now: now,+ }++ got := buildConnections(in)+ byID := map[string]Connection{}+ for _, connection := range got {+ byID[connection.ID] = connection+ }++ vmw := byID["vmware:vc1"]+ if vmw.State != ConnectionStateActive {+ t.Fatalf("vmware state = %q, want active", vmw.State)+ }+ if vmw.LastSeen == nil || !vmw.LastSeen.Equal(vmwareSuccess) {+ t.Fatalf("vmware lastSeen = %+v, want %s", vmw.LastSeen, vmwareSuccess)+ }+ if vmw.Fleet.CredentialStatus != fleetStateVerified || vmw.Fleet.CredentialHealth == nil || vmw.Fleet.CredentialHealth.Status != fleetStateVerified {+ t.Fatalf("vmware credential governance = %+v", vmw.Fleet)+ }++ tn := byID["truenas:tn1"]+ if tn.State != ConnectionStateActive {+ t.Fatalf("truenas state = %q, want active", tn.State)+ }+ if tn.LastSeen == nil || !tn.LastSeen.Equal(trueNASSuccess) {+ t.Fatalf("truenas lastSeen = %+v, want %s", tn.LastSeen, trueNASSuccess)+ }+ if tn.Fleet.CredentialStatus != fleetStateVerified || tn.Fleet.CredentialHealth == nil || tn.Fleet.CredentialHealth.Status != fleetStateVerified {+ t.Fatalf("truenas credential governance = %+v", tn.Fleet)+ }+}++func TestDeriveConnectionState_FirstPollFailureIsUnreachable(t *testing.T) {+ now := time.Now()+ h := healthEntry(nil, "connection refused", "network", "closed")+ state, reason, lastSeen, lastError := deriveConnectionState(true, h, now)+ if state != ConnectionStateUnreachable {+ t.Fatalf("state = %q, want unreachable", state)+ }+ if reason != "connection refused" {+ t.Fatalf("reason = %q, want connection refused", reason)+ }+ if lastSeen != nil {+ t.Fatalf("lastSeen = %+v, want nil", lastSeen)+ }+ if lastError == nil || lastError.Message != "connection refused" {+ t.Fatalf("lastError = %+v, want connection refused", lastError)+ }+}+func TestBuildConnections_UsesHealthLookup(t *testing.T) {now := time.Now()ls := now.Add(-15 * time.Second)diff --git a/internal/api/connections_alerts.go b/internal/api/connections_alerts.goindex 0f107db750..7cb83fd808 100644--- a/internal/api/connections_alerts.go+++ b/internal/api/connections_alerts.go@@ -11,12 +11,28 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/monitoring")+type aggregatorRuntimeSources struct {+ orgID string+ vmwarePoller *monitoring.VMwarePoller+ truenasPoller *monitoring.TrueNASPoller+}+// buildAggregatorInputs gathers the same inputs the HTTP connections handler// uses so the alerts pipeline can derive identical Connection rows without// going through the HTTP layer. Returning an empty aggregatorInputs when a// dependency is unavailable keeps the alerts loop a no-op rather than a hard// failure.func buildAggregatorInputs(ctx context.Context, cfg *config.Config, persistence *config.ConfigPersistence, monitor *monitoring.Monitor) aggregatorInputs {+ return buildAggregatorInputsWithRuntimeSources(ctx, cfg, persistence, monitor, aggregatorRuntimeSources{})+}++func buildAggregatorInputsWithRuntimeSources(+ ctx context.Context,+ cfg *config.Config,+ persistence *config.ConfigPersistence,+ monitor *monitoring.Monitor,+ runtime aggregatorRuntimeSources,+) aggregatorInputs {inputs := aggregatorInputs{now: time.Now()}if cfg != nil {@@ -37,6 +53,17 @@ func buildAggregatorInputs(ctx context.Context, cfg *config.Config, persistence}}+ orgID := runtime.orgID+ if orgID == "" {+ orgID = "default"+ }+ if runtime.vmwarePoller != nil && len(inputs.vmwareInstances) > 0 {+ inputs.vmwareSummaries = runtime.vmwarePoller.ConnectionSummaries(orgID, inputs.vmwareInstances)+ }+ if runtime.truenasPoller != nil && len(inputs.truenasInstances) > 0 {+ inputs.truenasSummaries = runtime.truenasPoller.ConnectionSummaries(orgID, inputs.truenasInstances)+ }+if monitor != nil {inputs.hosts = monitor.HostsSnapshot()inputs.agentDesiredConfigs = connectionAgentDesiredConfigFingerprints(monitor, inputs.hosts)@@ -115,6 +142,16 @@ func snapshotConnectionsForAlerts(connections []Connection) []alerts.ConnectionS// monitor-loop counterpart to the HTTP connections handler — it runs the// same derivation but skips the JSON envelope.func BuildAlertConnectionSnapshots(ctx context.Context, cfg *config.Config, persistence *config.ConfigPersistence, monitor *monitoring.Monitor) []alerts.ConnectionSnapshot {- inputs := buildAggregatorInputs(ctx, cfg, persistence, monitor)+ return buildAlertConnectionSnapshotsWithRuntimeSources(ctx, cfg, persistence, monitor, aggregatorRuntimeSources{})+}++func buildAlertConnectionSnapshotsWithRuntimeSources(+ ctx context.Context,+ cfg *config.Config,+ persistence *config.ConfigPersistence,+ monitor *monitoring.Monitor,+ runtime aggregatorRuntimeSources,+) []alerts.ConnectionSnapshot {+ inputs := buildAggregatorInputsWithRuntimeSources(ctx, cfg, persistence, monitor, runtime)return snapshotConnectionsForAlerts(buildConnections(inputs))}diff --git a/internal/api/connections_handlers.go b/internal/api/connections_handlers.goindex d90e9064bb..7bb0f39949 100644--- a/internal/api/connections_handlers.go+++ b/internal/api/connections_handlers.go@@ -13,9 +13,11 @@ import (// any persistence of its own — it composes per-type stores and the// monitoring scheduler's in-memory health data into a single list.type ConnectionsHandlers struct {- getConfig func(ctx context.Context) *config.Config- getPersistence func(ctx context.Context) *config.ConfigPersistence- getMonitor func(ctx context.Context) *monitoring.Monitor+ getConfig func(ctx context.Context) *config.Config+ getPersistence func(ctx context.Context) *config.ConfigPersistence+ getMonitor func(ctx context.Context) *monitoring.Monitor+ getTrueNASPoller func(ctx context.Context) *monitoring.TrueNASPoller+ getVMwarePoller func(ctx context.Context) *monitoring.VMwarePoller}// NewConnectionsHandlers wires the aggregator behind the request-scoped@@ -33,6 +35,19 @@ func NewConnectionsHandlers(}}+// SetPlatformPollers wires runtime poller summaries into the unified+// connections ledger for out-of-scheduler platform adapters.+func (h *ConnectionsHandlers) SetPlatformPollers(+ getTrueNASPoller func(ctx context.Context) *monitoring.TrueNASPoller,+ getVMwarePoller func(ctx context.Context) *monitoring.VMwarePoller,+) {+ if h == nil {+ return+ }+ h.getTrueNASPoller = getTrueNASPoller+ h.getVMwarePoller = getVMwarePoller+}+// HandleList returns every configured connection as a unified Connection row.// No probing or network I/O happens here — state is derived purely from// cached poller health.@@ -47,7 +62,7 @@ func (h *ConnectionsHandlers) HandleList(w http.ResponseWriter, r *http.Request)persistence := h.getPersistence(ctx)monitor := h.getMonitor(ctx)- inputs := buildAggregatorInputs(ctx, cfg, persistence, monitor)+ inputs := buildAggregatorInputsWithRuntimeSources(ctx, cfg, persistence, monitor, h.runtimeSources(ctx, resolveTenantOrgID(r)))connections := buildConnections(inputs)writeJSON(w, http.StatusOK, ConnectionsListResponse{@@ -56,6 +71,20 @@ func (h *ConnectionsHandlers) HandleList(w http.ResponseWriter, r *http.Request)})}+func (h *ConnectionsHandlers) runtimeSources(ctx context.Context, orgID string) aggregatorRuntimeSources {+ runtime := aggregatorRuntimeSources{orgID: orgID}+ if h == nil {+ return runtime+ }+ if h.getTrueNASPoller != nil {+ runtime.truenasPoller = h.getTrueNASPoller(ctx)+ }+ if h.getVMwarePoller != nil {+ runtime.vmwarePoller = h.getVMwarePoller(ctx)+ }+ return runtime+}+// HandleProbe fingerprints a user-supplied address and returns the product// types it detected, if any. No configuration is persisted — the caller// uses the response to pick a credential slot in ConnectionEditor.diff --git a/internal/api/connections_handlers_continuity_test.go b/internal/api/connections_handlers_continuity_test.goindex 979cfac47b..7ac4dbf130 100644--- a/internal/api/connections_handlers_continuity_test.go+++ b/internal/api/connections_handlers_continuity_test.go@@ -89,3 +89,70 @@ func TestConnectionsHandleListIncludesContinuityBackedHostAgents(t *testing.T) {t.Fatalf("expected continuity-backed connection to carry lastSeen, got %#v", conn.LastSeen)}}++func TestConnectionsHandleListUsesTrueNASPollerRuntimeSummary(t *testing.T) {+ persistence := config.NewConfigPersistence(t.TempDir())+ connection := config.TrueNASInstance{+ ID: "tn1",+ Name: "TrueNAS",+ Host: "truenas.lan",+ APIKey: "secret",+ UseHTTPS: true,+ Enabled: true,+ PollIntervalSecs: 60,+ MonitorDatasets: true,+ MonitorPools: true,+ MonitorReplication: true,+ }+ if err := persistence.SaveTrueNASConfig([]config.TrueNASInstance{connection}); err != nil {+ t.Fatalf("SaveTrueNASConfig: %v", err)+ }++ poller := monitoring.NewTrueNASPoller(nil, time.Minute, nil)+ successAt := time.Now().UTC().Add(-30 * time.Second)+ poller.RecordConnectionTestSuccess("default", connection.ID, connection, successAt)++ handler := NewConnectionsHandlers(+ func(context.Context) *config.Config { return nil },+ func(context.Context) *config.ConfigPersistence { return persistence },+ func(context.Context) *monitoring.Monitor { return nil },+ )+ handler.SetPlatformPollers(+ func(context.Context) *monitoring.TrueNASPoller { return poller },+ nil,+ )++ req := httptest.NewRequest(http.MethodGet, "/api/connections", nil)+ rec := httptest.NewRecorder()+ handler.HandleList(rec, req)+ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())+ }++ var resp ConnectionsListResponse+ if err := json.NewDecoder(rec.Body).Decode(&resp); err != nil {+ t.Fatalf("decode connections response: %v", err)+ }++ var tn *Connection+ for i := range resp.Connections {+ if resp.Connections[i].ID == "truenas:tn1" {+ tn = &resp.Connections[i]+ break+ }+ }+ if tn == nil {+ t.Fatalf("expected TrueNAS connection, got %+v", resp.Connections)+ }+ if tn.State != ConnectionStateActive {+ t.Fatalf("state = %q, want active", tn.State)+ }+ if tn.LastSeen == nil || !tn.LastSeen.Equal(successAt) {+ t.Fatalf("lastSeen = %+v, want %s", tn.LastSeen, successAt)+ }+ if tn.Fleet.CredentialStatus != fleetStateVerified ||+ tn.Fleet.CredentialHealth == nil ||+ tn.Fleet.CredentialHealth.Status != fleetStateVerified {+ t.Fatalf("credential governance = %+v", tn.Fleet)+ }+}diff --git a/internal/api/router.go b/internal/api/router.goindex f58f37a30e..c8f3b8ca9d 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -404,6 +404,10 @@ func (r *Router) setupRoutes() {r.configHandlers.getPersistence,r.configHandlers.getMonitor,)+ r.connectionsHandlers.SetPlatformPollers(+ func(context.Context) *monitoring.TrueNASPoller { return r.trueNASPoller },+ func(context.Context) *monitoring.VMwarePoller { return r.vmwarePoller },+ )if r.monitor != nil {// Drive the connection-degraded alert off the same aggregator the// HTTP handler uses, so the active-notification stream stays in@@ -412,9 +416,15 @@ func (r *Router) setupRoutes() {getCfg := r.configHandlers.getConfiggetPersist := r.configHandlers.getPersistencemonitor := r.monitor+ trueNASPoller := r.trueNASPoller+ vmwarePoller := r.vmwarePollerr.monitor.SetConnectionsSnapshotLister(func() []alerts.ConnectionSnapshot {ctx := context.Background()- return BuildAlertConnectionSnapshots(ctx, getCfg(ctx), getPersist(ctx), monitor)+ return buildAlertConnectionSnapshotsWithRuntimeSources(ctx, getCfg(ctx), getPersist(ctx), monitor, aggregatorRuntimeSources{+ orgID: "default",+ truenasPoller: trueNASPoller,+ vmwarePoller: vmwarePoller,+ })})}r.availabilityHandlers = NewAvailabilityHandlers(