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
frontend: resolve bare-hostname management URLs to LAN IPs from resource identity
rcourtman0f8e341bfb19
diff --git a/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts b/frontend-modern/src/utils/__tests__/resourceIdentity.test.tsindex fb5891b3d6..f5da208e28 100644--- a/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts+++ b/frontend-modern/src/utils/__tests__/resourceIdentity.test.ts@@ -15,10 +15,12 @@ import {getPreferredResourceDisplayName,getPreferredInfrastructureDisplayName,getPreferredResourceHostname,+ getPreferredResourceIP,getPreferredWorkloadsAgentHint,getPrimaryResourceIdentity,getPrimaryResourceIdentityRows,getResourceIdentityAliases,+ resolveGuestUrlWithIdentity,shouldShowResourcePlatformId,} from '@/utils/resourceIdentity';import type { Agent, Node } from '@/types/api';@@ -568,4 +570,61 @@ describe('resourceIdentity', () => {).toBe('prod-eu');}});++ describe('getPreferredResourceIP', () => {+ it('returns undefined when no identity IPs', () => {+ expect(getPreferredResourceIP(makeResource())).toBeUndefined();+ });++ it('prefers RFC 1918 private IPv4 over Tailscale and IPv6', () => {+ const resource = makeResource({+ identity: {+ ips: ['100.109.215.65', 'fd7a:115c:a1e0::f35:d741', 'fe80::1bf2:7ef4:cd4b:8d71', '192.168.0.2'],+ },+ });+ expect(getPreferredResourceIP(resource)).toBe('192.168.0.2');+ });++ it('falls back to any IPv4 when no RFC 1918 address', () => {+ const resource = makeResource({+ identity: { ips: ['100.64.0.1', 'fe80::1'] },+ });+ expect(getPreferredResourceIP(resource)).toBe('100.64.0.1');+ });+ });++ describe('resolveGuestUrlWithIdentity', () => {+ it('replaces bare hostname with LAN IP', () => {+ const resource = makeResource({+ identity: { ips: ['100.109.215.65', '192.168.0.2'] },+ });+ expect(resolveGuestUrlWithIdentity('https://pi:8006', resource)).toBe(+ 'https://192.168.0.2:8006',+ );+ });++ it('keeps URL that already uses an IP', () => {+ const resource = makeResource({ identity: { ips: ['192.168.0.2'] } });+ expect(resolveGuestUrlWithIdentity('https://192.168.0.5:8006', resource)).toBe(+ 'https://192.168.0.5:8006',+ );+ });++ it('keeps URL with FQDN hostname', () => {+ const resource = makeResource({ identity: { ips: ['192.168.0.2'] } });+ expect(resolveGuestUrlWithIdentity('https://delly.local:8006', resource)).toBe(+ 'https://delly.local:8006',+ );+ });++ it('returns original URL when no identity IPs available', () => {+ expect(resolveGuestUrlWithIdentity('https://pi:8006', makeResource())).toBe(+ 'https://pi:8006',+ );+ });++ it('handles empty URL', () => {+ expect(resolveGuestUrlWithIdentity('', makeResource())).toBe('');+ });+ });});diff --git a/frontend-modern/src/utils/resourceIdentity.ts b/frontend-modern/src/utils/resourceIdentity.tsindex 538b7b02e4..e7de713e61 100644--- a/frontend-modern/src/utils/resourceIdentity.ts+++ b/frontend-modern/src/utils/resourceIdentity.ts@@ -363,6 +363,42 @@ export const getPreferredInfrastructureDisplayName = (resource: Resource): stringetPreferredResourceHostname(resource) ||getPrimaryResourceIdentity(resource);+const IPV4_PATTERN = /^\d{1,3}(\.\d{1,3}){3}$/;++const isRfc1918Private = (ip: string): boolean => {+ if (!IPV4_PATTERN.test(ip)) return false;+ const [a, b] = ip.split('.').map(Number);+ return a === 10 || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168);+};++/**+ * Pick the best LAN IPv4 from a resource's identity, preferring RFC 1918+ * private addresses over Tailscale (100.64/10) or IPv6.+ */+export const getPreferredResourceIP = (resource: Resource): string | undefined => {+ const ips = resource.identity?.ips ?? [];+ if (ips.length === 0) return undefined;+ const lanIp = ips.find((ip) => isRfc1918Private(ip));+ if (lanIp) return lanIp;+ const ipv4 = ips.find((ip) => IPV4_PATTERN.test(ip));+ return ipv4;+};++/**+ * When a management URL uses a bare hostname (e.g. "https://pi:8006") that a+ * browser may not resolve, substitute the resource's known LAN IP.+ */+export const resolveGuestUrlWithIdentity = (url: string, resource: Resource): string => {+ if (!url) return url;+ const match = url.match(/^(https?:\/\/)([^:/]+)(:\d+)?(\/.*)?$/i);+ if (!match) return url;+ const [, protocol, hostname, port, path = ''] = match;+ if (IPV4_PATTERN.test(hostname) || hostname.includes(':')) return url;+ if (hostname.includes('.')) return url;+ const ip = getPreferredResourceIP(resource);+ return ip ? `${protocol}${ip}${port || ''}${path}` : url;+};+export const getPreferredWorkloadsAgentHint = (resource: Resource): string | undefined => {const platformData = getPlatformDataRecord(resource);const proxmox = platformData?.proxmox as Record<string, unknown> | undefined;diff --git a/frontend-modern/src/utils/resourceStateAdapters.ts b/frontend-modern/src/utils/resourceStateAdapters.tsindex 7bea089f34..77e48b62ab 100644--- a/frontend-modern/src/utils/resourceStateAdapters.ts+++ b/frontend-modern/src/utils/resourceStateAdapters.ts@@ -29,6 +29,7 @@ import {getPreferredInfrastructureDisplayName,getPreferredResourceClusterName,getPreferredResourceHostname,+ resolveGuestUrlWithIdentity,} from '@/utils/resourceIdentity';import {normalizeSourcePlatformScopes,@@ -934,11 +935,14 @@ export const nodeFromResource = (resource: Resource): Node | null => {host: name || preferredHostLabel,// proxmox.guestUrl is the operator-set link override and proxmox.host the// PVE API connection URL; `host` above stays a hostname label for display.- guestURL:+ guestURL: resolveGuestUrlWithIdentity(asString(proxmox?.guestUrl) ||- asString((resource as unknown as Record<string, unknown>).customURL) ||- asString((resource as unknown as Record<string, unknown>).customUrl) ||- asString(proxmox?.host),+ asString((resource as unknown as Record<string, unknown>).customURL) ||+ asString((resource as unknown as Record<string, unknown>).customUrl) ||+ asString(proxmox?.host) ||+ '',+ resource,+ ),status: resource.status || 'unknown',type: resource.type,cpu: resource.cpu?.current ?? 0,