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.

Move VMware connection health to poller

rcourtman7f7aab9f2517
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index fd02d6505c..87cf3aab5a 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -533,6 +533,12 @@ may show one VMware connection's poll health, last error classification, and
observed contribution summary, but it must not force the operator to manage
separate Automation API versus VI JSON sessions or understand multi-client
runtime wiring just to use the shared platform-connections path.
+That same shared connection model now also includes one runtime-health owner:
+manual saved-connection retests with no edit overlay must refresh the same
+poller-owned `poll` summary that ordinary list reads surface, while draft tests
+and edit-form overlay tests stay non-persistent until a save succeeds.
+Lifecycle-owned settings flows must not bring back a second `test` status model
+or a VMware-only health fetch just to describe row health.
That lifecycle-owned VMware slice now also includes the first live runtime
handoff rule. `frontend-modern/src/components/Settings/VMwareSettingsPanel.tsx`,
`frontend-modern/src/components/Settings/useVMwareSettingsPanelState.ts`,
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index a905493f48..5be63acabe 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -704,14 +704,18 @@ That same `/api/vmware/connections` family now also owns the current phase-1
implementation contract under `internal/api/vmware_handlers.go`,
`internal/api/router.go`, `internal/api/router_routes_registration.go`, and
`frontend-modern/src/api/vmware.ts`. The list response must carry one redacted
-stored connection shape plus canonical last-test status and observed
+stored connection shape plus canonical `poll` health and `observed`
contribution summary (`hosts`, `vms`, `datastores`, `viRelease`) so the shared
settings workspace can render VMware status without another provider-local
-inventory route. `POST /api/vmware/connections/test` must stay the draft test
-surface, while `POST /api/vmware/connections/{id}/test` remains the saved
-connection retest surface: a row-level saved retest with no payload should
-refresh the stored runtime summary, but an edit-form test overlay must preserve
-the stored summary until a real save succeeds. The explicit disabled path also
+inventory route. That `poll` payload is the canonical runtime contract:
+backend handlers must source it from the poller-owned per-connection summary,
+saved row-level retests with no payload must refresh that same summary owner,
+and edit-form overlay tests must preserve the stored summary until a real save
+succeeds. Compatibility acceptance of a historical `test` field may exist only
+inside shared frontend normalization; the backend route family itself must stay
+on `poll` for the operator-facing response model. `POST /api/vmware/connections/test`
+must stay the draft test surface, while `POST /api/vmware/connections/{id}/test`
+remains the saved connection retest surface. The explicit disabled path also
stays on this boundary: `404 vmware_disabled` means the operator or runtime has
opted out of the default-on VMware candidate, not that the platform requires a
different onboarding contract.
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index c0209a0c07..f89da312a1 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -101,6 +101,14 @@ health record, even if that provider keeps separate authenticated Automation
API and VI JSON clients internally. Connection edits that change host, auth,
TLS, or poll cadence must replace that live provider state instead of leaving
stale VMware sessions resident until restart.
+That same provider-owned summary must also serve the shared settings runtime
+surface. `internal/monitoring/vmware_poller.go` owns the per-connection poll
+summary (`poll` plus `observed`), `POST /api/vmware/connections/{id}/test`
+with no edit overlay must refresh that same summary owner, and
+`/api/vmware/connections` list reads must consume the poller summary instead of
+recomputing or shadowing it inside handler-local runtime state. Internal
+sub-second test harness intervals must not leak `intervalSeconds: 0` onto that
+operator-facing contract.
That provider ownership now has a concrete phase-1 runtime seam:
`internal/monitoring/vmware_poller.go` must keep VMware inventory on the
shared supplemental-ingest path, declare `SourceVMware` as its owned source,
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 7b7fd60de4..8313e964e7 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -91,7 +91,7 @@ querying, and the operator-facing storage health presentation layer.
25. Keep provider-backed poll cadence and settings-runtime health on the adjacent platform-connections contract. When shared `internal/api/` and poller wiring expose TrueNAS last-sync status, failure summaries, discovered contribution counts, manual saved-test status refresh, or platform handoff links in settings, storage and recovery may consume the resulting datasets, apps, disks, and recovery artifacts but must not redefine those settings-runtime health semantics or connection-level handoffs in storage/recovery-local transport or page flows.
26. Keep cross-surface recovery handoffs on the shared route-helper contract. When infrastructure or other unified-resource consumers expose TrueNAS recovery links, they must reuse the canonical `frontend-modern/src/routing/resourceLinks.ts` recovery builder with owned `platform` and `node` queries instead of inventing drawer-local recovery URLs or treating PBS services as the only infrastructure-to-recovery path.
27. Keep alert-side recovery drill-ins on that same shared route-helper contract. When alert investigation surfaces such as resource-incident panels expose recovery follow-up links for TrueNAS or future API-backed platforms, they must route through the canonical `frontend-modern/src/routing/resourceLinks.ts` recovery builder instead of freezing alert-local recovery URLs or introducing another provider-shaped recovery handoff vocabulary.
-28. Keep VMware onboarding runtime and recovery semantics separate on that same adjacent platform-connections contract. When `internal/api/router.go`, `internal/api/router_routes_registration.go`, or `internal/api/vmware_handlers.go` evolve VMware connection CRUD, saved-test refresh, or observed datastore/VM snapshot visibility, storage and recovery may consume the resulting shared context but must not treat those onboarding/runtime payloads as canonical recovery artifacts, restore capability, or recovery-local control transport.
+28. Keep VMware onboarding runtime and recovery semantics separate on that same adjacent platform-connections contract. When `internal/api/router.go`, `internal/api/router_routes_registration.go`, or `internal/api/vmware_handlers.go` evolve VMware connection CRUD, poller-owned `poll` / `observed` summary payloads, saved-test refresh, or observed datastore/VM snapshot visibility, storage and recovery may consume the resulting shared context but must not treat those onboarding/runtime payloads as canonical recovery artifacts, restore capability, or recovery-local control transport.
29. Keep VMware datastore projection on the shared unified-resource and storage-source contracts. When `frontend-modern/src/hooks/useUnifiedResources.ts` or shared `internal/api/router.go` wiring starts surfacing VMware-backed canonical `storage` resources, storage and recovery may expose those datastores through the owned `vmware-vsphere` source/platform vocabulary for inventory, capacity, and handoff flows only; they must not reinterpret that projection as VMware recovery support, restore semantics, or a provider-local protection surface.
30. Keep VMware placement and guest-detail enrichment descriptive on that same shared unified-resource contract. When `internal/vmware/provider.go`, `internal/unifiedresources/types.go`, and `frontend-modern/src/hooks/useUnifiedResources.ts` project datacenter, cluster, folder, runtime-host, datastore-attachment, guest-hostname, or guest-IP metadata onto canonical VMware `agent` / `vm` / `storage` resources, storage and recovery may use that detail for labeling and navigation only; they must not promote those topology or guest fields into recovery ownership, restore targeting, protection grouping, or a VMware-local recovery taxonomy without a separately governed slice.
31. Keep VMware datastore classification neutral on the shared storage adapter contract. When `frontend-modern/src/features/storageBackups/resourceStorageMapping.ts`, `frontend-modern/src/features/storageBackups/resourceStoragePresentation.ts`, and `frontend-modern/src/features/storageBackups/storageAdapters.ts` evolve canonical storage-record mapping, VMware-backed datastores must continue to land on the shared storage route as inventory-only datastores with neutral protection fallback, not as backup repositories, backup targets, or recovery-protected resources.
@@ -1643,7 +1643,8 @@ That same storage/recovery boundary also keeps the onboarding runtime separate
from recovery semantics. `internal/api/router.go`,
`internal/api/router_routes_registration.go`, and
`internal/api/vmware_handlers.go` may expose VMware connection CRUD, saved-test
-health refresh, and observed datastore/VM snapshot visibility on the shared
+health refresh, poller-owned `poll` / `observed` runtime summaries, and
+observed datastore/VM snapshot visibility on the shared
platform-connections surface, but storage and recovery must treat that data as
setup/runtime context only, not as proof that VMware has joined the canonical
recovery artifact or restore plane.
diff --git a/frontend-modern/src/api/__tests__/vmware.test.ts b/frontend-modern/src/api/__tests__/vmware.test.ts
index 9a8b6479a1..a8457539de 100644
--- a/frontend-modern/src/api/__tests__/vmware.test.ts
+++ b/frontend-modern/src/api/__tests__/vmware.test.ts
@@ -22,9 +22,11 @@ describe('VMwareAPI', () => {
password: ' ******** ',
insecureSkipVerify: true,
enabled: true,
- test: {
+ poll: {
+ intervalSeconds: 60,
lastAttemptAt: ' 2026-03-30T12:00:00Z ',
lastSuccessAt: ' 2026-03-30T12:00:01Z ',
+ consecutiveFailures: 0,
},
observed: {
collectedAt: ' 2026-03-30T12:00:02Z ',
@@ -46,9 +48,11 @@ describe('VMwareAPI', () => {
password: '********',
insecureSkipVerify: true,
enabled: true,
- test: {
+ poll: {
+ intervalSeconds: 60,
lastAttemptAt: '2026-03-30T12:00:00Z',
lastSuccessAt: '2026-03-30T12:00:01Z',
+ consecutiveFailures: 0,
lastError: undefined,
},
observed: {
diff --git a/frontend-modern/src/api/vmware.ts b/frontend-modern/src/api/vmware.ts
index e20bd0676b..70bff23dd6 100644
--- a/frontend-modern/src/api/vmware.ts
+++ b/frontend-modern/src/api/vmware.ts
@@ -12,20 +12,22 @@ const VMWARE_CONNECTIONS_PATH = '/api/vmware/connections';
const REDACTED_SECRET = '********';
type RawVMwareConnection = Partial<VMwareConnection>;
-type RawVMwareConnectionTestError = Partial<VMwareConnectionTestError>;
-type RawVMwareConnectionTest = Partial<VMwareConnectionTestStatus>;
+type RawVMwareConnectionPollError = Partial<VMwareConnectionPollError>;
+type RawVMwareConnectionPoll = Partial<VMwareConnectionPollStatus>;
type RawVMwareConnectionObservedSummary = Partial<VMwareConnectionObservedSummary>;
-export interface VMwareConnectionTestError {
+export interface VMwareConnectionPollError {
at?: string;
message?: string;
category?: string;
}
-export interface VMwareConnectionTestStatus {
+export interface VMwareConnectionPollStatus {
+ intervalSeconds?: number;
lastAttemptAt?: string;
lastSuccessAt?: string;
- lastError?: VMwareConnectionTestError;
+ consecutiveFailures?: number;
+ lastError?: VMwareConnectionPollError;
}
export interface VMwareConnectionObservedSummary {
@@ -45,7 +47,7 @@ export interface VMwareConnection {
password?: string;
insecureSkipVerify: boolean;
enabled: boolean;
- test?: VMwareConnectionTestStatus;
+ poll?: VMwareConnectionPollStatus;
observed?: VMwareConnectionObservedSummary;
}
@@ -63,9 +65,9 @@ export interface VMwareConnectionTestResult {
success: boolean;
}
-const normalizeVMwareConnectionTestError = (
- error: RawVMwareConnectionTestError | undefined,
-): VMwareConnectionTestError | undefined => {
+const normalizeVMwareConnectionPollError = (
+ error: RawVMwareConnectionPollError | undefined,
+): VMwareConnectionPollError | undefined => {
if (!error || typeof error !== 'object') return undefined;
return {
at: optionalTrimmedString(error.at),
@@ -74,14 +76,16 @@ const normalizeVMwareConnectionTestError = (
};
};
-const normalizeVMwareConnectionTest = (
- test: RawVMwareConnectionTest | undefined,
-): VMwareConnectionTestStatus | undefined => {
- if (!test || typeof test !== 'object') return undefined;
+const normalizeVMwareConnectionPoll = (
+ poll: RawVMwareConnectionPoll | undefined,
+): VMwareConnectionPollStatus | undefined => {
+ if (!poll || typeof poll !== 'object') return undefined;
return {
- lastAttemptAt: optionalTrimmedString(test.lastAttemptAt),
- lastSuccessAt: optionalTrimmedString(test.lastSuccessAt),
- lastError: normalizeVMwareConnectionTestError(test.lastError),
+ intervalSeconds: finiteNumberOrUndefined(poll.intervalSeconds),
+ lastAttemptAt: optionalTrimmedString(poll.lastAttemptAt),
+ lastSuccessAt: optionalTrimmedString(poll.lastSuccessAt),
+ consecutiveFailures: finiteNumberOrUndefined(poll.consecutiveFailures),
+ lastError: normalizeVMwareConnectionPollError(poll.lastError),
};
};
@@ -98,7 +102,9 @@ const normalizeVMwareConnectionObservedSummary = (
};
};
-const normalizeVMwareConnection = (connection: RawVMwareConnection): VMwareConnection => ({
+const normalizeVMwareConnection = (
+ connection: RawVMwareConnection & { test?: RawVMwareConnectionPoll },
+): VMwareConnection => ({
id: trimmedString(connection.id),
name: optionalTrimmedString(connection.name) ?? '',
host: trimmedString(connection.host),
@@ -107,7 +113,7 @@ const normalizeVMwareConnection = (connection: RawVMwareConnection): VMwareConne
password: optionalTrimmedString(connection.password),
insecureSkipVerify: strictBoolean(connection.insecureSkipVerify),
enabled: strictBoolean(connection.enabled),
- test: normalizeVMwareConnectionTest(connection.test),
+ poll: normalizeVMwareConnectionPoll(connection.poll ?? connection.test),
observed: normalizeVMwareConnectionObservedSummary(connection.observed),
});
diff --git a/frontend-modern/src/components/Settings/VMwareSettingsPanel.tsx b/frontend-modern/src/components/Settings/VMwareSettingsPanel.tsx
index b9310256c1..ecb053e40e 100644
--- a/frontend-modern/src/components/Settings/VMwareSettingsPanel.tsx
+++ b/frontend-modern/src/components/Settings/VMwareSettingsPanel.tsx
@@ -37,37 +37,37 @@ const getConnectionHealthPresentation = (connection: VMwareConnection) => {
};
}
- const test = connection.test;
- const lastSuccessAt = test?.lastSuccessAt;
- const lastError = test?.lastError;
+ const poll = connection.poll;
+ const lastSuccessAt = poll?.lastSuccessAt;
+ const lastError = poll?.lastError;
const lastErrorAfterSuccess =
!!lastError?.at &&
(!lastSuccessAt || new Date(lastError.at).getTime() >= new Date(lastSuccessAt).getTime());
if (lastError && lastErrorAfterSuccess) {
return {
- label: 'Validation failing',
+ label: 'Runtime failing',
className: 'bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-300',
detail: lastError.at
- ? `Last validation ${formatRelativeTime(lastError.at, { compact: true })}`
- : 'Last validation failed',
+ ? `Last check ${formatRelativeTime(lastError.at, { compact: true })}`
+ : 'Last check failed',
error: lastError.message || null,
};
}
if (lastSuccessAt) {
return {
- label: 'Validated',
+ label: 'Healthy',
className: 'bg-emerald-50 text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-300',
- detail: `Last validation ${formatRelativeTime(lastSuccessAt, { compact: true })}`,
+ detail: `Last check ${formatRelativeTime(lastSuccessAt, { compact: true })}`,
error: null,
};
}
return {
- label: 'Awaiting first validation',
+ label: 'Awaiting first poll',
className: 'bg-amber-50 text-amber-700 dark:bg-amber-950/40 dark:text-amber-300',
- detail: 'Pulse has not completed the first vCenter validation yet',
+ detail: 'Pulse has not completed the first vCenter poll yet',
error: null,
};
};
@@ -247,7 +247,7 @@ export const VMwareSettingsPanel: Component<VMwareSettingsPanelProps> = (props)
<span>Skip TLS verification</span>
</>
</Show>
- <Show when={connection.test?.lastAttemptAt || health().detail}>
+ <Show when={connection.poll?.lastAttemptAt || health().detail}>
<>
<span aria-hidden="true">•</span>
<span>{health().detail}</span>
@@ -267,7 +267,7 @@ export const VMwareSettingsPanel: Component<VMwareSettingsPanelProps> = (props)
<div class="flex flex-wrap gap-2">
<Show when={connection.observed?.collectedAt}>
<span class={connectionMetaBadgeClass}>
- Validated{' '}
+ Observed{' '}
{formatRelativeTime(connection.observed?.collectedAt, {
compact: true,
})}
diff --git a/frontend-modern/src/components/Settings/__tests__/VMwareSettingsPanel.test.tsx b/frontend-modern/src/components/Settings/__tests__/VMwareSettingsPanel.test.tsx
index dd13b1b99e..d7a40e90d5 100644
--- a/frontend-modern/src/components/Settings/__tests__/VMwareSettingsPanel.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/VMwareSettingsPanel.test.tsx
@@ -89,7 +89,7 @@ describe('VMwareSettingsPanel', () => {
password: '********',
insecureSkipVerify: false,
enabled: true,
- test: {
+ poll: {
lastSuccessAt: new Date(Date.now() - 60_000).toISOString(),
},
observed: {
@@ -115,7 +115,7 @@ describe('VMwareSettingsPanel', () => {
expect(screen.getByText('VMware vSphere platform integration')).toBeInTheDocument();
expect(screen.getByText('VMware connections')).toBeInTheDocument();
expect(screen.getByText('lab-vcenter')).toBeInTheDocument();
- expect(screen.getByText('Validated')).toBeInTheDocument();
+ expect(screen.getByText('Healthy')).toBeInTheDocument();
expect(
within(screen.getByTestId('vmware-connection-conn-2')).getAllByText('Disabled'),
).toHaveLength(2);
diff --git a/frontend-modern/src/components/Settings/__tests__/useVMwareSettingsPanelState.test.tsx b/frontend-modern/src/components/Settings/__tests__/useVMwareSettingsPanelState.test.tsx
index 80de5e3aa0..0d5b567be0 100644
--- a/frontend-modern/src/components/Settings/__tests__/useVMwareSettingsPanelState.test.tsx
+++ b/frontend-modern/src/components/Settings/__tests__/useVMwareSettingsPanelState.test.tsx
@@ -129,7 +129,7 @@ describe('useVMwareSettingsPanelState', () => {
password: '********',
insecureSkipVerify: false,
enabled: true,
- test: {
+ poll: {
lastSuccessAt: '2026-03-30T10:00:00Z',
},
},
@@ -148,7 +148,7 @@ describe('useVMwareSettingsPanelState', () => {
'VMware connection successful for lab-vcenter',
);
expect(VMwareAPI.listConnections).toHaveBeenCalledTimes(2);
- expect(result.connections()[0].test?.lastSuccessAt).toBe('2026-03-30T10:00:00Z');
+ expect(result.connections()[0].poll?.lastSuccessAt).toBe('2026-03-30T10:00:00Z');
});
it('tests edited saved connections through the canonical saved-connection API path', async () => {
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 518b24af68..4dc9fbd79a 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -167,6 +167,8 @@ func TestContract_VMwareSavedConnectionTestsUpdateRuntimeSummary(t *testing.T) {
Enabled: true,
}
handler, persistence := newVMwareHandlersForTest(t)
+ poller := monitoring.NewVMwarePoller(nil, time.Minute)
+ handler.getPoller = func(context.Context) *monitoring.VMwarePoller { return poller }
if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{connection}); err != nil {
t.Fatalf("seed vmware config: %v", err)
}
@@ -185,12 +187,12 @@ func TestContract_VMwareSavedConnectionTestsUpdateRuntimeSummary(t *testing.T) {
if rec.Code != http.StatusOK {
t.Fatalf("expected 200, got %d: %s", rec.Code, rec.Body.String())
}
- status := handler.runtimeStatus(connection.ID)
- if status.Test == nil || status.Test.LastSuccessAt == nil {
- t.Fatalf("expected saved manual test to refresh runtime summary, got %+v", status.Test)
+ summary := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{connection})[connection.ID]
+ if summary.Poll == nil || summary.Poll.LastSuccessAt == nil {
+ t.Fatalf("expected saved manual test to refresh runtime summary, got %+v", summary.Poll)
}
- if status.Observed == nil || status.Observed.VMs != 20 {
- t.Fatalf("expected saved manual test to refresh observed summary, got %+v", status.Observed)
+ if summary.Observed == nil || summary.Observed.VMs != 20 {
+ t.Fatalf("expected saved manual test to refresh observed summary, got %+v", summary.Observed)
}
}
@@ -207,12 +209,14 @@ func TestContract_VMwareConnectionListCarriesObservedSummary(t *testing.T) {
Enabled: true,
}
handler, persistence := newVMwareHandlersForTest(t)
+ poller := monitoring.NewVMwarePoller(nil, time.Minute)
+ handler.getPoller = func(context.Context) *monitoring.VMwarePoller { return poller }
if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{connection}); err != nil {
t.Fatalf("seed vmware config: %v", err)
}
collectedAt := time.Date(2026, 3, 30, 18, 0, 0, 0, time.UTC)
- handler.recordTestSuccess(connection.ID, &vmware.InventorySummary{
+ poller.RecordConnectionTestSuccess("default", connection.ID, &vmware.InventorySummary{
Hosts: 4,
VMs: 24,
Datastores: 6,
@@ -237,6 +241,9 @@ func TestContract_VMwareConnectionListCarriesObservedSummary(t *testing.T) {
if responses[0].Password != "********" {
t.Fatalf("expected redacted password in vmware list response, got %q", responses[0].Password)
}
+ if responses[0].Poll == nil || responses[0].Poll.LastSuccessAt == nil {
+ t.Fatalf("expected poll summary in vmware list response, got %+v", responses[0])
+ }
if responses[0].Observed == nil {
t.Fatalf("expected observed summary in vmware list response, got %+v", responses[0])
}
diff --git a/internal/api/router.go b/internal/api/router.go
index f3af99b59c..ab106fe968 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -355,6 +355,7 @@ func (r *Router) setupRoutes() {
}
r.vmwareHandlers = &VMwareHandlers{
getPersistence: r.configHandlers.getPersistence,
+ getPoller: func(context.Context) *monitoring.VMwarePoller { return r.vmwarePoller },
}
recoveryManager := recoverymanager.New(r.multiTenant)
r.recoveryHandlers = NewRecoveryHandlers(recoveryManager)
diff --git a/internal/api/vmware_handlers.go b/internal/api/vmware_handlers.go
index febe8b4cb6..718a3ad87f 100644
--- a/internal/api/vmware_handlers.go
+++ b/internal/api/vmware_handlers.go
@@ -13,6 +13,7 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/config"
"github.com/rcourtman/pulse-go-rewrite/internal/mock"
+ "github.com/rcourtman/pulse-go-rewrite/internal/monitoring"
"github.com/rcourtman/pulse-go-rewrite/internal/vmware"
)
@@ -21,6 +22,7 @@ const vmwareConnectionsPathPrefix = "/api/vmware/connections/"
// VMwareHandlers manages VMware vCenter connection CRUD and connectivity checks.
type VMwareHandlers struct {
getPersistence func(ctx context.Context) *config.ConfigPersistence
+ getPoller func(ctx context.Context) *monitoring.VMwarePoller
newClient func(vmware.ClientConfig) (vmwareClient, error)
statusMu sync.RWMutex
@@ -34,33 +36,13 @@ type vmwareClient interface {
type vmwareConnectionResponse struct {
config.VMwareVCenterInstance
- Test *vmwareConnectionTestStatus `json:"test,omitempty"`
- Observed *vmwareConnectionObservedStatus `json:"observed,omitempty"`
-}
-
-type vmwareConnectionTestStatus struct {
- LastAttemptAt *time.Time `json:"lastAttemptAt,omitempty"`
- LastSuccessAt *time.Time `json:"lastSuccessAt,omitempty"`
- LastError *vmwareConnectionTestError `json:"lastError,omitempty"`
-}
-
-type vmwareConnectionTestError struct {
- At *time.Time `json:"at,omitempty"`
- Message string `json:"message,omitempty"`
- Category string `json:"category,omitempty"`
-}
-
-type vmwareConnectionObservedStatus struct {
- CollectedAt *time.Time `json:"collectedAt,omitempty"`
- Hosts int `json:"hosts"`
- VMs int `json:"vms"`
- Datastores int `json:"datastores"`
- VIRelease string `json:"viRelease,omitempty"`
+ Poll *monitoring.VMwareConnectionPollStatus `json:"poll,omitempty"`
+ Observed *monitoring.VMwareConnectionObservedSummary `json:"observed,omitempty"`
}
type vmwareConnectionRuntimeStatus struct {
- Test *vmwareConnectionTestStatus
- Observed *vmwareConnectionObservedStatus
+ Poll *monitoring.VMwareConnectionPollStatus
+ Observed *monitoring.VMwareConnectionObservedSummary
}
// HandleAdd stores a new VMware vCenter connection.
@@ -130,16 +112,31 @@ func (h *VMwareHandlers) HandleList(w http.ResponseWriter, r *http.Request) {
return
}
+ orgID := resolveTenantOrgID(r)
+ var summaries map[string]monitoring.VMwareConnectionSummary
+ if h != nil && h.getPoller != nil {
+ if poller := h.getPoller(r.Context()); poller != nil {
+ summaries = poller.ConnectionSummaries(orgID, instances)
+ }
+ }
+
responses := make([]vmwareConnectionResponse, 0, len(instances))
for i := range instances {
item := instances[i]
item.ApplyDefaults()
- status := h.runtimeStatus(strings.TrimSpace(item.ID))
- responses = append(responses, vmwareConnectionResponse{
+ response := vmwareConnectionResponse{
VMwareVCenterInstance: item.Redacted(),
- Test: status.Test,
- Observed: status.Observed,
- })
+ }
+ connID := strings.TrimSpace(item.ID)
+ if summary, ok := summaries[connID]; ok {
+ response.Poll = summary.Poll
+ response.Observed = summary.Observed
+ } else {
+ status := h.runtimeStatus(connID)
+ response.Poll = status.Poll
+ response.Observed = status.Observed
+ }
+ responses = append(responses, response)
}
writeJSON(w, http.StatusOK, responses)
@@ -338,13 +335,23 @@ func (h *VMwareHandlers) HandleTestSavedConnection(w http.ResponseWriter, r *htt
summary, invalidConfig, err := h.testConnectionInstance(r, instance)
if err != nil {
if !hasPayload {
- h.recordTestFailure(connectionID, err, time.Now().UTC())
+ at := time.Now().UTC()
+ if poller := h.pollerForRequest(r.Context()); poller != nil {
+ poller.RecordConnectionTestFailure(resolveTenantOrgID(r), connectionID, err, at)
+ } else {
+ h.recordTestFailure(connectionID, err, at)
+ }
}
h.writeConnectionFailure(w, invalidConfig, err)
return
}
if !hasPayload {
- h.recordTestSuccess(connectionID, summary, time.Now().UTC())
+ at := time.Now().UTC()
+ if poller := h.pollerForRequest(r.Context()); poller != nil {
+ poller.RecordConnectionTestSuccess(resolveTenantOrgID(r), connectionID, summary, at)
+ } else {
+ h.recordTestSuccess(connectionID, summary, at)
+ }
}
writeJSON(w, http.StatusOK, map[string]any{"success": true})
return
@@ -484,6 +491,13 @@ func (h *VMwareHandlers) persistenceForRequest(w http.ResponseWriter, ctx contex
return persistence
}
+func (h *VMwareHandlers) pollerForRequest(ctx context.Context) *monitoring.VMwarePoller {
+ if h == nil || h.getPoller == nil {
+ return nil
+ }
+ return h.getPoller(ctx)
+}
+
func (h *VMwareHandlers) runtimeStatus(connectionID string) vmwareConnectionRuntimeStatus {
if h == nil {
return vmwareConnectionRuntimeStatus{}
@@ -510,12 +524,13 @@ func (h *VMwareHandlers) recordTestSuccess(connectionID string, summary *vmware.
h.statuses = make(map[string]vmwareConnectionRuntimeStatus)
}
current := h.statuses[connectionID]
- current.Test = &vmwareConnectionTestStatus{
- LastAttemptAt: timePointer(at),
- LastSuccessAt: timePointer(at),
+ current.Poll = &monitoring.VMwareConnectionPollStatus{
+ IntervalSeconds: defaultVMwarePollIntervalSeconds(),
+ LastAttemptAt: timePointer(at),
+ LastSuccessAt: timePointer(at),
}
if summary != nil {
- current.Observed = &vmwareConnectionObservedStatus{
+ current.Observed = &monitoring.VMwareConnectionObservedSummary{
CollectedAt: timePointer(at),
Hosts: summary.Hosts,
VMs: summary.VMs,
@@ -536,17 +551,19 @@ func (h *VMwareHandlers) recordTestFailure(connectionID string, err error, at ti
h.statuses = make(map[string]vmwareConnectionRuntimeStatus)
}
current := h.statuses[connectionID]
- test := current.Test
- if test == nil {
- test = &vmwareConnectionTestStatus{}
+ poll := current.Poll
+ if poll == nil {
+ poll = &monitoring.VMwareConnectionPollStatus{
+ IntervalSeconds: defaultVMwarePollIntervalSeconds(),
+ }
}
- test.LastAttemptAt = timePointer(at)
- test.LastError = &vmwareConnectionTestError{
+ poll.LastAttemptAt = timePointer(at)
+ poll.LastError = &monitoring.VMwareConnectionPollError{
At: timePointer(at),
Message: err.Error(),
Category: connectionErrorCategory(err),
}
- current.Test = test
+ current.Poll = poll
h.statuses[connectionID] = current
}
@@ -564,22 +581,22 @@ func (h *VMwareHandlers) clearRuntimeStatus(connectionID string) {
func cloneVMwareRuntimeStatus(status vmwareConnectionRuntimeStatus) vmwareConnectionRuntimeStatus {
cloned := vmwareConnectionRuntimeStatus{}
- if status.Test != nil {
- test := *status.Test
- if test.LastAttemptAt != nil {
- test.LastAttemptAt = timePointer(*test.LastAttemptAt)
+ if status.Poll != nil {
+ poll := *status.Poll
+ if poll.LastAttemptAt != nil {
+ poll.LastAttemptAt = timePointer(*poll.LastAttemptAt)
}
- if test.LastSuccessAt != nil {
- test.LastSuccessAt = timePointer(*test.LastSuccessAt)
+ if poll.LastSuccessAt != nil {
+ poll.LastSuccessAt = timePointer(*poll.LastSuccessAt)
}
- if test.LastError != nil {
- errCopy := *test.LastError
+ if poll.LastError != nil {
+ errCopy := *poll.LastError
if errCopy.At != nil {
errCopy.At = timePointer(*errCopy.At)
}
- test.LastError = &errCopy
+ poll.LastError = &errCopy
}
- cloned.Test = &test
+ cloned.Poll = &poll
}
if status.Observed != nil {
observed := *status.Observed
@@ -591,6 +608,10 @@ func cloneVMwareRuntimeStatus(status vmwareConnectionRuntimeStatus) vmwareConnec
return cloned
}
+func defaultVMwarePollIntervalSeconds() int {
+ return int((60 * time.Second) / time.Second)
+}
+
func timePointer(value time.Time) *time.Time {
v := value
return &v
diff --git a/internal/api/vmware_handlers_test.go b/internal/api/vmware_handlers_test.go
index 3b387e077d..78f4a217eb 100644
--- a/internal/api/vmware_handlers_test.go
+++ b/internal/api/vmware_handlers_test.go
@@ -13,6 +13,7 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/config"
"github.com/rcourtman/pulse-go-rewrite/internal/mock"
+ "github.com/rcourtman/pulse-go-rewrite/internal/monitoring"
"github.com/rcourtman/pulse-go-rewrite/internal/vmware"
)
@@ -121,6 +122,8 @@ func TestVMwareHandlers_HandleList_RedactsSensitiveFieldsAndIncludesRuntimeSumma
setVMwareFeatureForTest(t, true)
handler, persistence := newVMwareHandlersForTest(t)
+ poller := monitoring.NewVMwarePoller(nil, time.Minute)
+ handler.getPoller = func(context.Context) *monitoring.VMwarePoller { return poller }
if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{
{
ID: "vc-1",
@@ -137,7 +140,7 @@ func TestVMwareHandlers_HandleList_RedactsSensitiveFieldsAndIncludesRuntimeSumma
}
recordedAt := time.Date(2026, 3, 30, 10, 11, 12, 0, time.UTC)
- handler.recordTestSuccess("vc-1", &vmware.InventorySummary{
+ poller.RecordConnectionTestSuccess("default", "vc-1", &vmware.InventorySummary{
Hosts: 3,
VMs: 42,
Datastores: 6,
@@ -162,8 +165,8 @@ func TestVMwareHandlers_HandleList_RedactsSensitiveFieldsAndIncludesRuntimeSumma
if listed[0].Password != "********" {
t.Fatalf("expected password to be redacted, got %q", listed[0].Password)
}
- if listed[0].Test == nil || listed[0].Test.LastSuccessAt == nil {
- t.Fatalf("expected saved test runtime summary, got %+v", listed[0].Test)
+ if listed[0].Poll == nil || listed[0].Poll.LastSuccessAt == nil {
+ t.Fatalf("expected saved test runtime summary, got %+v", listed[0].Poll)
}
if listed[0].Observed == nil {
t.Fatalf("expected observed summary, got nil")
@@ -204,7 +207,7 @@ func TestVMwareHandlers_HandleDelete_RemovesAndClearsRuntimeSummary(t *testing.T
if len(stored) != 1 || stored[0].ID != "beta" {
t.Fatalf("expected only beta to remain, got %+v", stored)
}
- if status := handler.runtimeStatus("alpha"); status.Test != nil || status.Observed != nil {
+ if status := handler.runtimeStatus("alpha"); status.Poll != nil || status.Observed != nil {
t.Fatalf("expected runtime summary to be cleared, got %+v", status)
}
}
@@ -401,6 +404,8 @@ func TestVMwareHandlers_HandleTestSavedConnection_UsesStoredSecretsAndUpdatesRun
Enabled: true,
}
handler, persistence := newVMwareHandlersForTest(t)
+ poller := monitoring.NewVMwarePoller(nil, time.Minute)
+ handler.getPoller = func(context.Context) *monitoring.VMwarePoller { return poller }
if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{connection}); err != nil {
t.Fatalf("seed vmware config: %v", err)
}
@@ -437,7 +442,7 @@ func TestVMwareHandlers_HandleTestSavedConnection_UsesStoredSecretsAndUpdatesRun
if err := json.NewDecoder(listRec.Body).Decode(&listed); err != nil {
t.Fatalf("decode list response: %v", err)
}
- if len(listed) != 1 || listed[0].Test == nil || listed[0].Test.LastSuccessAt == nil {
+ if len(listed) != 1 || listed[0].Poll == nil || listed[0].Poll.LastSuccessAt == nil {
t.Fatalf("expected saved retest to update runtime status, got %+v", listed)
}
if listed[0].Observed == nil || listed[0].Observed.VMs != 25 {
@@ -456,6 +461,8 @@ func TestVMwareHandlers_HandleTestSavedConnection_UpdatesRuntimeSummaryFailure(t
Enabled: true,
}
handler, persistence := newVMwareHandlersForTest(t)
+ poller := monitoring.NewVMwarePoller(nil, time.Minute)
+ handler.getPoller = func(context.Context) *monitoring.VMwarePoller { return poller }
if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{connection}); err != nil {
t.Fatalf("seed vmware config: %v", err)
}
@@ -475,12 +482,12 @@ func TestVMwareHandlers_HandleTestSavedConnection_UpdatesRuntimeSummaryFailure(t
t.Fatalf("expected 400, got %d: %s", rec.Code, rec.Body.String())
}
- status := handler.runtimeStatus(connection.ID)
- if status.Test == nil || status.Test.LastError == nil {
- t.Fatalf("expected saved retest failure to update runtime summary, got %+v", status.Test)
+ summary := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{connection})[connection.ID]
+ if summary.Poll == nil || summary.Poll.LastError == nil {
+ t.Fatalf("expected saved retest failure to update runtime summary, got %+v", summary.Poll)
}
- if status.Test.LastError.Message != "authentication failed" || status.Test.LastError.Category != "auth" {
- t.Fatalf("unexpected failure summary: %+v", status.Test.LastError)
+ if summary.Poll.LastError.Message != "authentication failed" || summary.Poll.LastError.Category != "auth" {
+ t.Fatalf("unexpected failure summary: %+v", summary.Poll.LastError)
}
}
@@ -488,6 +495,8 @@ func TestVMwareHandlers_HandleTestSavedConnection_MergesEditedPayloadWithoutOver
setVMwareFeatureForTest(t, true)
handler, persistence := newVMwareHandlersForTest(t)
+ poller := monitoring.NewVMwarePoller(nil, time.Minute)
+ handler.getPoller = func(context.Context) *monitoring.VMwarePoller { return poller }
if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{
{
ID: "conn-1",
@@ -504,7 +513,7 @@ func TestVMwareHandlers_HandleTestSavedConnection_MergesEditedPayloadWithoutOver
}
previousAt := time.Date(2026, 3, 30, 9, 0, 0, 0, time.UTC)
- handler.recordTestSuccess("conn-1", &vmware.InventorySummary{Hosts: 1, VMs: 2, Datastores: 3, VIRelease: "8.0.2.0"}, previousAt)
+ poller.RecordConnectionTestSuccess("default", "conn-1", &vmware.InventorySummary{Hosts: 1, VMs: 2, Datastores: 3, VIRelease: "8.0.2.0"}, previousAt)
var gotConfig vmware.ClientConfig
handler.newClient = func(cfg vmware.ClientConfig) (vmwareClient, error) {
@@ -543,12 +552,21 @@ func TestVMwareHandlers_HandleTestSavedConnection_MergesEditedPayloadWithoutOver
t.Fatalf("expected stored password to be reused, got %+v", gotConfig)
}
- status := handler.runtimeStatus("conn-1")
- if status.Observed == nil || status.Observed.VMs != 2 || status.Observed.VIRelease != "8.0.2.0" {
- t.Fatalf("expected existing runtime summary to remain unchanged, got %+v", status.Observed)
+ summary := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{{
+ ID: "conn-1",
+ Name: "lab-vcenter",
+ Host: "vcsa.lab.local",
+ Port: 443,
+ Username: "[email protected]",
+ Password: "super-secret",
+ InsecureSkipVerify: false,
+ Enabled: true,
+ }})["conn-1"]
+ if summary.Observed == nil || summary.Observed.VMs != 2 || summary.Observed.VIRelease != "8.0.2.0" {
+ t.Fatalf("expected existing runtime summary to remain unchanged, got %+v", summary.Observed)
}
- if status.Test == nil || status.Test.LastSuccessAt == nil || !status.Test.LastSuccessAt.Equal(previousAt) {
- t.Fatalf("expected existing last success timestamp to remain unchanged, got %+v", status.Test)
+ if summary.Poll == nil || summary.Poll.LastSuccessAt == nil || !summary.Poll.LastSuccessAt.Equal(previousAt) {
+ t.Fatalf("expected existing last success timestamp to remain unchanged, got %+v", summary.Poll)
}
}
diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.go
index 667e3eaf35..7981578048 100644
--- a/internal/monitoring/canonical_guardrails_test.go
+++ b/internal/monitoring/canonical_guardrails_test.go
@@ -122,6 +122,9 @@ func TestVMwarePollerUsesCanonicalSupplementalIngestOwnership(t *testing.T) {
"func (p *VMwarePoller) SnapshotOwnedSources() []unifiedresources.DataSource {",
"return []unifiedresources.DataSource{unifiedresources.SourceVMware}",
"return vmware.NewAPIProvider(vmware.ProviderMetadata{",
+ "func (p *VMwarePoller) ConnectionSummaries(orgID string, instances []config.VMwareVCenterInstance) map[string]VMwareConnectionSummary {",
+ "func (p *VMwarePoller) RecordConnectionTestSuccess(orgID, connID string, summary *vmware.InventorySummary, at time.Time) {",
+ "func (p *VMwarePoller) RecordConnectionTestFailure(orgID, connID string, err error, at time.Time) {",
}
for _, snippet := range requiredSnippets {
if !strings.Contains(source, snippet) {
diff --git a/internal/monitoring/vmware_poller.go b/internal/monitoring/vmware_poller.go
index 89858af21b..2764c23af4 100644
--- a/internal/monitoring/vmware_poller.go
+++ b/internal/monitoring/vmware_poller.go
@@ -2,6 +2,7 @@ package monitoring
import (
"context"
+ "errors"
"sort"
"strings"
"sync"
@@ -15,10 +16,54 @@ import (
const defaultVMwarePollInterval = 60 * time.Second
+// VMwareConnectionPollError captures the last runtime poll error for one
+// configured VMware connection.
+type VMwareConnectionPollError struct {
+ At *time.Time `json:"at,omitempty"`
+ Message string `json:"message,omitempty"`
+ Category string `json:"category,omitempty"`
+}
+
+// VMwareConnectionPollStatus summarizes the runtime polling state for one
+// configured VMware connection.
+type VMwareConnectionPollStatus struct {
+ IntervalSeconds int `json:"intervalSeconds"`
+ LastAttemptAt *time.Time `json:"lastAttemptAt,omitempty"`
+ LastSuccessAt *time.Time `json:"lastSuccessAt,omitempty"`
+ ConsecutiveFailures int `json:"consecutiveFailures,omitempty"`
+ LastError *VMwareConnectionPollError `json:"lastError,omitempty"`
+}
+
+// VMwareConnectionObservedSummary summarizes the canonical resources the most
+// recent successful poll contributed for one configured VMware connection.
+type VMwareConnectionObservedSummary struct {
+ CollectedAt *time.Time `json:"collectedAt,omitempty"`
+ Hosts int `json:"hosts"`
+ VMs int `json:"vms"`
+ Datastores int `json:"datastores"`
+ VIRelease string `json:"viRelease,omitempty"`
+}
+
+// VMwareConnectionSummary merges poll health with the most recent discovered
+// platform contribution for one configured VMware connection.
+type VMwareConnectionSummary struct {
+ Poll *VMwareConnectionPollStatus `json:"poll,omitempty"`
+ Observed *VMwareConnectionObservedSummary `json:"observed,omitempty"`
+}
+
+type vmwareConnectionRuntimeStatus struct {
+ lastAttemptAt time.Time
+ lastSuccessAt time.Time
+ lastError *VMwareConnectionPollError
+ consecutiveFailures int
+ observed *VMwareConnectionObservedSummary
+}
+
type vmwarePollerProvider interface {
Refresh(ctx context.Context) error
Records() []unifiedresources.IngestRecord
ActivityChanges() []unifiedresources.ResourceChange
+ Snapshot() *vmware.InventorySnapshot
Close()
}
@@ -31,6 +76,8 @@ type VMwarePoller struct {
providersByOrg map[string]map[string]vmwarePollerProvider
// configsByOrg is keyed by orgID, then connection ID.
configsByOrg map[string]map[string]config.VMwareVCenterInstance
+ // statusByOrg is keyed by orgID, then connection ID.
+ statusByOrg map[string]map[string]*vmwareConnectionRuntimeStatus
// cachedRecordsByOrg is keyed by orgID, then connection ID.
cachedRecordsByOrg map[string]map[string][]unifiedresources.IngestRecord
// cachedChangesByOrg is keyed by orgID, then connection ID.
@@ -62,6 +109,7 @@ func NewVMwarePoller(multiTenant *config.MultiTenantPersistence, interval time.D
multiTenant: multiTenant,
providersByOrg: make(map[string]map[string]vmwarePollerProvider),
configsByOrg: make(map[string]map[string]config.VMwareVCenterInstance),
+ statusByOrg: make(map[string]map[string]*vmwareConnectionRuntimeStatus),
cachedRecordsByOrg: make(map[string]map[string][]unifiedresources.IngestRecord),
cachedChangesByOrg: make(map[string]map[string][]unifiedresources.ResourceChange),
stopped: stopped,
@@ -241,6 +289,9 @@ func (p *VMwarePoller) syncConnections() {
if p.cachedChangesByOrg[orgID] == nil {
p.cachedChangesByOrg[orgID] = make(map[string][]unifiedresources.ResourceChange)
}
+ if p.statusByOrg[orgID] == nil {
+ p.statusByOrg[orgID] = make(map[string]*vmwareConnectionRuntimeStatus)
+ }
for connectionID, instance := range connectionMap {
existingConfig, exists := p.configsByOrg[orgID][connectionID]
@@ -292,11 +343,15 @@ func (p *VMwarePoller) syncConnections() {
if p.configsByOrg[orgID] != nil {
delete(p.configsByOrg[orgID], connectionID)
}
+ if p.statusByOrg[orgID] != nil {
+ delete(p.statusByOrg[orgID], connectionID)
+ }
}
if len(providers) == 0 {
delete(p.providersByOrg, orgID)
delete(p.configsByOrg, orgID)
+ delete(p.statusByOrg, orgID)
delete(p.cachedRecordsByOrg, orgID)
delete(p.cachedChangesByOrg, orgID)
}
@@ -317,7 +372,11 @@ func (p *VMwarePoller) pollConnection(ctx context.Context, entry vmwarePollerPro
pollCtx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
+ at := time.Now().UTC()
if err := entry.provider.Refresh(pollCtx); err != nil {
+ p.mu.Lock()
+ p.recordConnectionFailureLocked(entry.orgID, entry.connectionID, err, at)
+ p.mu.Unlock()
log.Warn().
Str("component", "vmware_poller").
Str("action", "refresh").
@@ -330,8 +389,10 @@ func (p *VMwarePoller) pollConnection(ctx context.Context, entry vmwarePollerPro
records := cloneIngestRecords(entry.provider.Records())
changes := cloneResourceChanges(entry.provider.ActivityChanges())
+ snapshot := entry.provider.Snapshot()
p.mu.Lock()
+ p.recordConnectionSuccessLocked(entry.orgID, entry.connectionID, at, snapshot)
if p.cachedRecordsByOrg[entry.orgID] == nil {
p.cachedRecordsByOrg[entry.orgID] = make(map[string][]unifiedresources.IngestRecord)
}
@@ -399,6 +460,67 @@ func (p *VMwarePoller) nextWaitDuration(now time.Time) time.Duration {
return p.interval
}
+// ConnectionSummaries returns per-connection runtime poll health and discovered
+// contribution summaries for the supplied VMware settings records.
+func (p *VMwarePoller) ConnectionSummaries(orgID string, instances []config.VMwareVCenterInstance) map[string]VMwareConnectionSummary {
+ if len(instances) == 0 {
+ return nil
+ }
+
+ orgID = normalizeVMwareOrgID(orgID)
+ summaries := make(map[string]VMwareConnectionSummary, len(instances))
+ intervalSeconds := defaultVMwareConnectionPollIntervalSeconds()
+ if p != nil {
+ intervalSeconds = p.connectionPollIntervalSeconds()
+ }
+
+ for i := range instances {
+ instance := instances[i]
+ instance.ApplyDefaults()
+ connID := strings.TrimSpace(instance.ID)
+ if connID == "" {
+ continue
+ }
+
+ summary := VMwareConnectionSummary{
+ Poll: &VMwareConnectionPollStatus{
+ IntervalSeconds: int(intervalSeconds),
+ },
+ }
+
+ if p != nil {
+ p.mu.Lock()
+ status := p.cloneRuntimeStatusLocked(orgID, connID)
+ p.mu.Unlock()
+ if status != nil {
+ summary.Poll.LastAttemptAt = cloneTimePointer(status.LastAttemptAt)
+ summary.Poll.LastSuccessAt = cloneTimePointer(status.LastSuccessAt)
+ summary.Poll.ConsecutiveFailures = status.ConsecutiveFailures
+ summary.Poll.LastError = cloneVMwareConnectionPollError(status.LastError)
+ summary.Observed = cloneVMwareObservedSummary(status.Observed)
+ }
+ }
+
+ summaries[connID] = summary
+ }
+
+ return summaries
+}
+
+func (p *VMwarePoller) connectionPollIntervalSeconds() int {
+ if p == nil {
+ return defaultVMwareConnectionPollIntervalSeconds()
+ }
+ if p.interval < time.Second {
+ return defaultVMwareConnectionPollIntervalSeconds()
+ }
+ return int(p.interval / time.Second)
+}
+
+func defaultVMwareConnectionPollIntervalSeconds() int {
+ return int(defaultVMwarePollInterval / time.Second)
+}
+
// GetCurrentRecords returns the latest known VMware records for the default org.
func (p *VMwarePoller) GetCurrentRecords() []unifiedresources.IngestRecord {
return p.GetCurrentRecordsForOrg("default")
@@ -528,3 +650,173 @@ func cloneResourceChanges(in []unifiedresources.ResourceChange) []unifiedresourc
}
return out
}
+
+func (p *VMwarePoller) cloneRuntimeStatusLocked(orgID string, connID string) *vmwareConnectionRuntimeSnapshot {
+ if p == nil {
+ return nil
+ }
+ byConn := p.statusByOrg[orgID]
+ if byConn == nil {
+ return nil
+ }
+ status := byConn[connID]
+ if status == nil {
+ return nil
+ }
+ return &vmwareConnectionRuntimeSnapshot{
+ LastAttemptAt: timePointerIfSet(status.lastAttemptAt),
+ LastSuccessAt: timePointerIfSet(status.lastSuccessAt),
+ ConsecutiveFailures: status.consecutiveFailures,
+ LastError: cloneVMwareConnectionPollError(status.lastError),
+ Observed: cloneVMwareObservedSummary(status.observed),
+ }
+}
+
+type vmwareConnectionRuntimeSnapshot struct {
+ LastAttemptAt *time.Time
+ LastSuccessAt *time.Time
+ ConsecutiveFailures int
+ LastError *VMwareConnectionPollError
+ Observed *VMwareConnectionObservedSummary
+}
+
+func (p *VMwarePoller) ensureConnectionRuntimeStatusLocked(orgID, connID string) *vmwareConnectionRuntimeStatus {
+ if p.statusByOrg[orgID] == nil {
+ p.statusByOrg[orgID] = make(map[string]*vmwareConnectionRuntimeStatus)
+ }
+ if p.statusByOrg[orgID][connID] == nil {
+ p.statusByOrg[orgID][connID] = &vmwareConnectionRuntimeStatus{}
+ }
+ return p.statusByOrg[orgID][connID]
+}
+
+func (p *VMwarePoller) recordConnectionSuccessLocked(orgID, connID string, at time.Time, snapshot *vmware.InventorySnapshot) {
+ status := p.ensureConnectionRuntimeStatusLocked(orgID, connID)
+ status.lastAttemptAt = at
+ status.lastSuccessAt = at
+ status.lastError = nil
+ status.consecutiveFailures = 0
+ if snapshot != nil {
+ status.observed = buildVMwareObservedSummary(snapshot)
+ }
+}
+
+func (p *VMwarePoller) recordConnectionFailureLocked(orgID, connID string, err error, at time.Time) {
+ if err == nil {
+ return
+ }
+ status := p.ensureConnectionRuntimeStatusLocked(orgID, connID)
+ status.lastAttemptAt = at
+ status.consecutiveFailures++
+ status.lastError = &VMwareConnectionPollError{
+ At: timePointerIfSet(at),
+ Message: strings.TrimSpace(err.Error()),
+ Category: classifyVMwarePollError(err),
+ }
+}
+
+// RecordConnectionTestSuccess updates one saved VMware connection summary after
+// a manual row-level test using the same canonical runtime health owner as the
+// live poller.
+func (p *VMwarePoller) RecordConnectionTestSuccess(orgID, connID string, summary *vmware.InventorySummary, at time.Time) {
+ if p == nil {
+ return
+ }
+ connID = strings.TrimSpace(connID)
+ if connID == "" {
+ return
+ }
+ orgID = normalizeVMwareOrgID(orgID)
+
+ p.mu.Lock()
+ defer p.mu.Unlock()
+ status := p.ensureConnectionRuntimeStatusLocked(orgID, connID)
+ status.lastAttemptAt = at
+ status.lastSuccessAt = at
+ status.lastError = nil
+ status.consecutiveFailures = 0
+ if summary != nil {
+ status.observed = &VMwareConnectionObservedSummary{
+ CollectedAt: timePointerIfSet(at),
+ Hosts: summary.Hosts,
+ VMs: summary.VMs,
+ Datastores: summary.Datastores,
+ VIRelease: strings.TrimSpace(summary.VIRelease),
+ }
+ }
+}
+
+// RecordConnectionTestFailure updates one saved VMware connection summary after
+// a manual row-level test failure while preserving previously observed
+// contribution summary.
+func (p *VMwarePoller) RecordConnectionTestFailure(orgID, connID string, err error, at time.Time) {
+ if p == nil || err == nil {
+ return
+ }
+ connID = strings.TrimSpace(connID)
+ if connID == "" {
+ return
+ }
+ orgID = normalizeVMwareOrgID(orgID)
+
+ p.mu.Lock()
+ defer p.mu.Unlock()
+ p.recordConnectionFailureLocked(orgID, connID, err, at)
+}
+
+func buildVMwareObservedSummary(snapshot *vmware.InventorySnapshot) *VMwareConnectionObservedSummary {
+ if snapshot == nil {
+ return nil
+ }
+ collectedAt := snapshot.CollectedAt
+ return &VMwareConnectionObservedSummary{
+ CollectedAt: timePointerIfSet(collectedAt),
+ Hosts: len(snapshot.Hosts),
+ VMs: len(snapshot.VMs),
+ Datastores: len(snapshot.Datastores),
+ VIRelease: strings.TrimSpace(snapshot.VIRelease),
+ }
+}
+
+func classifyVMwarePollError(err error) string {
+ if err == nil {
+ return ""
+ }
+ var connectionErr *vmware.ConnectionError
+ if errors.As(err, &connectionErr) && connectionErr != nil {
+ return strings.TrimSpace(connectionErr.Category)
+ }
+ return ""
+}
+
+func normalizeVMwareOrgID(orgID string) string {
+ orgID = strings.TrimSpace(orgID)
+ if orgID == "" {
+ return "default"
+ }
+ return orgID
+}
+
+func cloneVMwareConnectionPollError(value *VMwareConnectionPollError) *VMwareConnectionPollError {
+ if value == nil {
+ return nil
+ }
+ return &VMwareConnectionPollError{
+ At: cloneTimePointer(value.At),
+ Message: strings.TrimSpace(value.Message),
+ Category: strings.TrimSpace(value.Category),
+ }
+}
+
+func cloneVMwareObservedSummary(value *VMwareConnectionObservedSummary) *VMwareConnectionObservedSummary {
+ if value == nil {
+ return nil
+ }
+ return &VMwareConnectionObservedSummary{
+ CollectedAt: cloneTimePointer(value.CollectedAt),
+ Hosts: value.Hosts,
+ VMs: value.VMs,
+ Datastores: value.Datastores,
+ VIRelease: strings.TrimSpace(value.VIRelease),
+ }
+}
diff --git a/internal/monitoring/vmware_poller_test.go b/internal/monitoring/vmware_poller_test.go
index 84cf42883e..bf61690b7c 100644
--- a/internal/monitoring/vmware_poller_test.go
+++ b/internal/monitoring/vmware_poller_test.go
@@ -2,6 +2,7 @@ package monitoring
import (
"context"
+ "errors"
"testing"
"time"
@@ -114,6 +115,19 @@ func TestVMwarePollerPollsConfiguredConnections(t *testing.T) {
if supplemental := poller.SupplementalChanges(nil, "default"); len(supplemental) != 2 {
t.Fatalf("expected SupplementalChanges to mirror cached VMware changes, got %d", len(supplemental))
}
+
+ waitForCondition(t, 2*time.Second, func() bool {
+ summary, ok := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{connection})[connection.ID]
+ return ok && summary.Poll != nil && summary.Poll.LastSuccessAt != nil && summary.Observed != nil
+ }, "expected VMware poller to publish connection summary")
+
+ summary := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{connection})[connection.ID]
+ if summary.Poll == nil || summary.Poll.IntervalSeconds != 60 {
+ t.Fatalf("expected VMware poll interval 60, got %+v", summary.Poll)
+ }
+ if summary.Observed == nil || summary.Observed.Hosts != 1 || summary.Observed.VMs != 1 || summary.Observed.Datastores != 1 {
+ t.Fatalf("unexpected observed summary: %+v", summary.Observed)
+ }
}
func TestVMwarePollerFeatureFlagGate(t *testing.T) {
@@ -146,3 +160,102 @@ func TestVMwarePollerFeatureFlagGate(t *testing.T) {
t.Fatalf("expected no VMware records when feature flag is disabled, got %d", len(records))
}
}
+
+func TestVMwarePollerConnectionSummariesCaptureFailuresWithoutClearingObservedSummary(t *testing.T) {
+ poller := NewVMwarePoller(nil, time.Minute)
+ connection := config.NewVMwareVCenterInstance()
+ connection.ID = "vc-1"
+ connection.Host = "vc.lab.local"
+ connection.Username = "[email protected]"
+ connection.Password = "secret"
+
+ successAt := time.Date(2026, 3, 31, 9, 0, 0, 0, time.UTC)
+ failureAt := successAt.Add(5 * time.Minute)
+ poller.RecordConnectionTestSuccess("default", connection.ID, &vmware.InventorySummary{
+ Hosts: 2,
+ VMs: 14,
+ Datastores: 3,
+ VIRelease: "8.0.3",
+ }, successAt)
+ poller.RecordConnectionTestFailure("default", connection.ID, &vmware.ConnectionError{
+ Category: "permission",
+ Message: "VMware permissions are insufficient for vmware performance metrics",
+ }, failureAt)
+
+ summary := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{connection})[connection.ID]
+ if summary.Poll == nil || summary.Poll.LastError == nil {
+ t.Fatalf("expected poll failure summary, got %+v", summary.Poll)
+ }
+ if summary.Poll.ConsecutiveFailures != 1 || summary.Poll.LastError.Category != "permission" {
+ t.Fatalf("unexpected poll failure details: %+v", summary.Poll)
+ }
+ if summary.Observed == nil || summary.Observed.VMs != 14 || summary.Observed.VIRelease != "8.0.3" {
+ t.Fatalf("expected observed summary to be preserved after failure, got %+v", summary.Observed)
+ }
+}
+
+type failingVMwarePollerProvider struct {
+ err error
+}
+
+func (p *failingVMwarePollerProvider) Refresh(context.Context) error { return p.err }
+func (p *failingVMwarePollerProvider) Records() []unifiedresources.IngestRecord { return nil }
+func (p *failingVMwarePollerProvider) ActivityChanges() []unifiedresources.ResourceChange {
+ return nil
+}
+func (p *failingVMwarePollerProvider) Snapshot() *vmware.InventorySnapshot { return nil }
+func (p *failingVMwarePollerProvider) Close() {}
+
+func TestVMwarePollerLiveFailureKeepsCachedRecords(t *testing.T) {
+ previous := vmware.IsFeatureEnabled()
+ vmware.SetFeatureEnabled(true)
+ t.Cleanup(func() { vmware.SetFeatureEnabled(previous) })
+
+ mtp, persistence := newTestTenantPersistence(t)
+ connection := config.NewVMwareVCenterInstance()
+ connection.ID = "vc-live-fail"
+ connection.Host = "vc.fail.local"
+ connection.Username = "[email protected]"
+ connection.Password = "secret"
+ if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{connection}); err != nil {
+ t.Fatalf("SaveVMwareConfig() error = %v", err)
+ }
+
+ providerCalls := 0
+ poller := NewVMwarePoller(mtp, 20*time.Millisecond)
+ poller.newProvider = func(instance config.VMwareVCenterInstance) (vmwarePollerProvider, error) {
+ providerCalls++
+ if providerCalls == 1 {
+ return vmware.NewProvider(vmware.InventorySnapshot{
+ ConnectionID: instance.ID,
+ CollectedAt: time.Now().UTC(),
+ VIRelease: "8.0.3",
+ Hosts: []vmware.InventoryHost{{Host: "host-1", Name: "esxi-01"}},
+ }), nil
+ }
+ return &failingVMwarePollerProvider{
+ err: errors.New("refresh vmware inventory: VMware permissions are insufficient for vmware performance metrics"),
+ }, nil
+ }
+ poller.syncConnections()
+ poller.pollAll(context.Background())
+
+ initialRecords := poller.GetCurrentRecordsForOrg("default")
+ if len(initialRecords) != 1 {
+ t.Fatalf("expected initial cached VMware records, got %d", len(initialRecords))
+ }
+
+ poller.providersByOrg["default"][connection.ID] = &failingVMwarePollerProvider{
+ err: &vmware.ConnectionError{Category: "permission", Message: "VMware permissions are insufficient for vmware performance metrics"},
+ }
+ poller.pollAll(context.Background())
+
+ recordsAfterFailure := poller.GetCurrentRecordsForOrg("default")
+ if len(recordsAfterFailure) != 1 {
+ t.Fatalf("expected cached VMware records to survive live failure, got %d", len(recordsAfterFailure))
+ }
+ summary := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{connection})[connection.ID]
+ if summary.Poll == nil || summary.Poll.LastError == nil || summary.Poll.LastError.Category != "permission" {
+ t.Fatalf("expected permission poll error after live failure, got %+v", summary.Poll)
+ }
+}
diff --git a/internal/vmware/client.go b/internal/vmware/client.go
index 958374d1a0..48ccaf3c26 100644
--- a/internal/vmware/client.go
+++ b/internal/vmware/client.go
@@ -198,6 +198,7 @@ func (c *Client) CollectInventory(ctx context.Context) (*InventorySnapshot, erro
if err := c.enrichInventoryTopology(ctx, automationSessionID, release, sessionID, inventory); err != nil {
return nil, err
}
+ inventory.VIRelease = strings.TrimSpace(release)
inventory.CollectedAt = time.Now().UTC()
return inventory, nil
}
diff --git a/internal/vmware/provider.go b/internal/vmware/provider.go
index 60821c6ffc..ca96e242a6 100644
--- a/internal/vmware/provider.go
+++ b/internal/vmware/provider.go
@@ -143,6 +143,7 @@ type InventorySnapshot struct {
ConnectionID string
ConnectionName string
VCenterHost string
+ VIRelease string
CollectedAt time.Time
Hosts []InventoryHost
VMs []InventoryVM
diff --git a/tests/integration/tests/22-vmware-settings-platform-connections.spec.ts b/tests/integration/tests/22-vmware-settings-platform-connections.spec.ts
index 915c3e66d8..73bdce308c 100644
--- a/tests/integration/tests/22-vmware-settings-platform-connections.spec.ts
+++ b/tests/integration/tests/22-vmware-settings-platform-connections.spec.ts
@@ -76,7 +76,7 @@ test.describe('VMware platform connections settings', () => {
password: '********',
insecureSkipVerify: false,
enabled: true,
- test: {
+ poll: {
lastSuccessAt: healthyAt,
},
observed: {
@@ -96,7 +96,7 @@ test.describe('VMware platform connections settings', () => {
password: '********',
insecureSkipVerify: true,
enabled: true,
- test: {
+ poll: {
lastAttemptAt: failingAt,
lastError: {
at: failingAt,
@@ -141,7 +141,7 @@ test.describe('VMware platform connections settings', () => {
const primaryCard = page.getByTestId('vmware-connection-vmware-1');
await expect(primaryCard).toContainText('Primary vCenter');
- await expect(primaryCard).toContainText('Validated');
+ await expect(primaryCard).toContainText('Healthy');
await expect(primaryCard).toContainText('6 hosts');
await expect(primaryCard).toContainText('120 vms');
await expect(primaryCard).toContainText('18 datastores');
@@ -149,7 +149,7 @@ test.describe('VMware platform connections settings', () => {
const failingCard = page.getByTestId('vmware-connection-vmware-2');
await expect(failingCard).toContainText('Staging vCenter');
- await expect(failingCard).toContainText('Validation failing');
+ await expect(failingCard).toContainText('Runtime failing');
await expect(failingCard).toContainText('authentication failed');
await expect(failingCard).toContainText('Skip TLS verification');
@@ -206,7 +206,7 @@ test.describe('VMware platform connections settings', () => {
password: '********',
insecureSkipVerify: createPayload.insecureSkipVerify,
enabled: createPayload.enabled,
- test: {
+ poll: {
lastSuccessAt: validatedAt,
},
observed: {
@@ -251,7 +251,7 @@ test.describe('VMware platform connections settings', () => {
password: '********',
insecureSkipVerify: updatePayload.insecureSkipVerify,
enabled: updatePayload.enabled,
- test: {
+ poll: {
lastSuccessAt: validatedAt,
},
observed: {
@@ -322,7 +322,7 @@ test.describe('VMware platform connections settings', () => {
const connectionCard = page.getByTestId('vmware-connection-conn-1');
await expect(connectionCard).toBeVisible();
await expect(connectionCard).toContainText('Lab vCenter');
- await expect(connectionCard).toContainText('Validated');
+ await expect(connectionCard).toContainText('Healthy');
await expect.poll(() => createPayload).toMatchObject({
name: 'Lab vCenter',
host: 'vcsa.lab.local',