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.

Order physical interface IPs ahead of virtual bridges in host identity

rcourtmane339af2a6ee2
diff --git a/internal/unifiedresources/adapters.go b/internal/unifiedresources/adapters.go
index 1fd98ce4f3..86edfc1363 100644
--- a/internal/unifiedresources/adapters.go
+++ b/internal/unifiedresources/adapters.go
@@ -3672,21 +3672,54 @@ func convertSwarm(info *models.DockerSwarmInfo) *DockerSwarmInfo {
func collectInterfaceIDs(interfaces []models.HostNetworkInterface) ([]string, []string) {
var ips []string
var macs []string
- for _, iface := range interfaces {
- if iface.MAC != "" {
- macs = append(macs, iface.MAC)
- }
- for _, addr := range iface.Addresses {
- ip := addr
- if strings.Contains(ip, "/") {
- ip = strings.Split(ip, "/")[0]
+ // Agents report interfaces sorted by name, which places docker0/br-* bridges
+ // ahead of eth*/en*, and consumers treat the first IP as the host's primary
+ // address. Collect physical-looking interfaces first so bridge and overlay
+ // addresses never lead the list. Mirrors hostagent.isLikelyVirtualInterfaceName.
+ for pass := 0; pass < 2; pass++ {
+ for _, iface := range interfaces {
+ if (pass == 0) == isLikelyVirtualInterfaceName(iface.Name) {
+ continue
+ }
+ if iface.MAC != "" {
+ macs = append(macs, iface.MAC)
+ }
+ for _, addr := range iface.Addresses {
+ ip := addr
+ if strings.Contains(ip, "/") {
+ ip = strings.Split(ip, "/")[0]
+ }
+ ips = append(ips, ip)
}
- ips = append(ips, ip)
}
}
return ips, macs
}
+func isLikelyVirtualInterfaceName(name string) bool {
+ name = strings.ToLower(strings.TrimSpace(name))
+ switch {
+ case name == "" || name == "lo":
+ return true
+ case strings.HasPrefix(name, "docker"):
+ return true
+ case strings.HasPrefix(name, "veth"):
+ return true
+ case strings.HasPrefix(name, "br-"):
+ return true
+ case strings.HasPrefix(name, "cni"):
+ return true
+ case strings.HasPrefix(name, "flannel"):
+ return true
+ case strings.HasPrefix(name, "virbr"):
+ return true
+ case strings.HasPrefix(name, "zt"):
+ return true
+ default:
+ return false
+ }
+}
+
func extractHostname(raw string) string {
raw = strings.TrimSpace(raw)
if raw == "" {
diff --git a/internal/unifiedresources/adapters_test.go b/internal/unifiedresources/adapters_test.go
index 698130fe04..c15e732791 100644
--- a/internal/unifiedresources/adapters_test.go
+++ b/internal/unifiedresources/adapters_test.go
@@ -1731,3 +1731,34 @@ func TestResourceFromDockerContainerAdvertisesUpdateCapabilityOnlyWithDigest(t *
t.Fatalf("capabilities without available update = %#v, want stop/restart only", got)
}
}
+
+func TestCollectInterfaceIDsOrdersPhysicalInterfacesFirst(t *testing.T) {
+ interfaces := []models.HostNetworkInterface{
+ {Name: "br-8f2a1c3d", MAC: "02:42:aa:bb:cc:01", Addresses: []string{"172.18.0.1/16"}},
+ {Name: "docker0", MAC: "02:42:aa:bb:cc:02", Addresses: []string{"172.17.0.1/16"}},
+ {Name: "eth0", MAC: "aa:bb:cc:dd:ee:ff", Addresses: []string{"192.168.1.50/24"}},
+ }
+
+ ips, macs := collectInterfaceIDs(interfaces)
+
+ if len(ips) != 3 || ips[0] != "192.168.1.50" {
+ t.Fatalf("expected physical interface IP first, got %v", ips)
+ }
+ if ips[1] != "172.18.0.1" || ips[2] != "172.17.0.1" {
+ t.Fatalf("expected bridge IPs to follow in report order, got %v", ips)
+ }
+ if len(macs) != 3 || macs[0] != "aa:bb:cc:dd:ee:ff" {
+ t.Fatalf("expected physical interface MAC first, got %v", macs)
+ }
+}
+
+func TestCollectInterfaceIDsAllVirtualStillCollects(t *testing.T) {
+ interfaces := []models.HostNetworkInterface{
+ {Name: "docker0", Addresses: []string{"172.17.0.1/16"}},
+ }
+
+ ips, _ := collectInterfaceIDs(interfaces)
+ if len(ips) != 1 || ips[0] != "172.17.0.1" {
+ t.Fatalf("expected virtual-only host to keep its address, got %v", ips)
+ }
+}