diff --git a/internal/alerts/host.go b/internal/alerts/host.go index c5bfb4763..ab5fe1902 100644 --- a/internal/alerts/host.go +++ b/internal/alerts/host.go @@ -27,16 +27,29 @@ func stripHostResourcePrefix(resourceID string) string { } func hostDisplayName(host models.Host) string { + base := "Agent" if name := strings.TrimSpace(host.DisplayName); name != "" { - return name + base = name + } else if name := strings.TrimSpace(host.Hostname); name != "" { + base = name + } else if host.ID != "" { + base = host.ID } - if name := strings.TrimSpace(host.Hostname); name != "" { - return name + + // When a host agent is linked to a Proxmox node/VM/container, qualify its + // name so its alerts are not confused with the linked resource's alerts. + if strings.TrimSpace(host.LinkedNodeID) != "" || + strings.TrimSpace(host.LinkedVMID) != "" || + strings.TrimSpace(host.LinkedContainerID) != "" { + if strings.EqualFold(base, "Agent") { + return "Host Agent" + } + if !strings.Contains(strings.ToLower(base), "host agent") { + return fmt.Sprintf("%s (Host Agent)", base) + } } - if host.ID != "" { - return host.ID - } - return "Agent" + + return base } func hostInstanceName(host models.Host) string { @@ -316,7 +329,7 @@ func (m *Manager) CheckHost(host models.Host) { // Use specific resource ID for the disk: hostID/disk-temp:device tempResourceID := fmt.Sprintf("%s/disk_temp:%s", hostResourceID(host.ID), sanitizeHostComponent(disk.Device)) - tempResourceName := fmt.Sprintf("%s (%s Temp)", host.DisplayName, disk.Device) + tempResourceName := fmt.Sprintf("%s (%s Temp)", hostDisplayName(host), disk.Device) diskTempMetadata := cloneMetadata(baseMetadata) diskTempMetadata["metric"] = "diskTemperature" diff --git a/internal/alerts/utility_test.go b/internal/alerts/utility_test.go index 20282f725..a4781633c 100644 --- a/internal/alerts/utility_test.go +++ b/internal/alerts/utility_test.go @@ -710,6 +710,33 @@ func TestHostDisplayName(t *testing.T) { }, want: "Server Name", }, + { + name: "linked host agent display name is qualified", + host: models.Host{ + ID: "id-123", + DisplayName: "Hamster", + LinkedVMID: "Main:node1:101", + }, + want: "Hamster (Host Agent)", + }, + { + name: "linked host agent hostname fallback is qualified", + host: models.Host{ + ID: "id-123", + Hostname: "proxmoxn3", + LinkedContainerID: "Main:node1:102", + }, + want: "proxmoxn3 (Host Agent)", + }, + { + name: "existing host agent suffix is not duplicated", + host: models.Host{ + ID: "id-123", + DisplayName: "Hamster (Host Agent)", + LinkedNodeID: "Main-node1", + }, + want: "Hamster (Host Agent)", + }, } for _, tc := range tests {