mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-07-09 16:00:59 +00:00
Disambiguate linked host-agent alert names
Back-port v5 fix a4834ed80 to v6. hostDisplayName now appends
'(Host Agent)' (or returns 'Host Agent' for an unnamed agent) when the
host is linked to a Proxmox node/VM/container, and the disk-temperature
resource name uses hostDisplayName(host) instead of host.DisplayName.
Without this, a host agent running alongside the Proxmox node/VM it is
linked to produced alerts with an identical name, making them
indistinguishable. Adapted to v6's 'Agent' fallback. Adds test cases.
This commit is contained in:
parent
85ec355268
commit
15657d9a0a
2 changed files with 48 additions and 8 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue