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.

Alert on a host sensor's temperature from its own threshold

rcourtman92aae26d3406
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 6ba41d5ac9..74a395c204 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -4288,7 +4288,10 @@ candidates are reviewed in batched `QuickAnalysis` calls of at most
`patrolAlertReviewBatchSize` alerts with numbered per-alert verdict
lines; verdict parsing is fail-safe (unparseable or out-of-range
verdicts default to KEEP, a bare `RESOLVE:` response is honored only
-for single-alert batches), and the recorded usage events carry use
+for single-alert batches; a native sensor alert, `agent:<host>/sensor:<hex>`,
+is always kept, because the review snapshot carries no native sensor reading
+that could show it recovered, as `TestPatrolReviewNeverResolvesNativeSensorAlerts`
+pins), and the recorded usage events carry use
case `patrol` with `TargetType` `alert_autoresolve` so cost telemetry
can decompose alert-review spend from the main Patrol analysis pass.
This replaced the prior one-model-call-per-alert-per-run loop that
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index 9bded06e06..a28f2de9d6 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -1669,6 +1669,66 @@ type, severity and metric fields. Presentation must advertise the backend-owned
template data rather than asking operators to parse the English alert message
or reach into metadata for canonical alert identity.
+### Native sensor temperatures alert only on their own threshold
+
+A host agent's native lm-sensors temperature (`HostSensorSummary.Native`, kind
+`temperature`) raises an alert only when its own override sets a threshold:
+`AlertConfig.Overrides["agent:<host ID>/sensor:<hex>"].Temperature`, where
+`<hex>` is the lower-case hex of the sensor ID's UTF-8 bytes
+(`HostNativeSensorResourceID`), so IDs that differ only by case or
+punctuation stay apart after the lower-casing host child IDs and metric names
+receive. A sensor has no default and never inherits the host's, a linked
+node's or a guest's CPU `Temperature`; a missing, disabled or zero override
+raises nothing. The alert uses the canonical metric path with metric
+`temperature` and spec resource type `agent-sensor` (a migration bridge type
+in spec validation), so its ID is
+`agent:<host>/sensor:<hex>::metric-threshold:temperature`, it inherits the
+temperature stability delay, critical escalation and performance quiet-hours
+category, and its message names the sensor's label. Fan inputs raise nothing.
+
+The spec resource type is also the runtime classification, so
+`agent-sensor` delay and intent rules apply on top of the agent ones.
+
+An invalid reading, a reading without a value, a configured sensor missing
+from the report, an empty inventory and telemetry expiry interrupt the run and
+hold a firing alert: the inventory carries no completeness state, so absence is
+not evidence of removal. The hold is not indefinite: like any alert, one with
+no observation for 24 hours is auto-resolved by the stale sweep as no longer
+monitored, and retention cleanup applies as usual. Removing, disabling or
+zeroing the override, switching off the host's or all agents' alerting, and
+removing the host resolve it and drop its pending run; cleanup walks active,
+reducer-pending and intent-pending state as well as configured overrides, so
+removing an override still reaches its run. A confirmed offline host clears
+the alert with its other child alerts. A configuration save re-judges a firing
+sensor alert by its own override only, and interrupts a pending run when the
+save switched off its threshold, its host (directly or through an inherited
+linked-resource override), all agents or global alerting, using the host link
+identity recorded with the run; a run without that identity is interrupted.
+A re-enabled threshold therefore cannot reuse earlier grace. In `CheckHost`,
+global alerts-off returns early without clearing, as for the other host
+children; telemetry expiry with alerting off clears them. Clearing all active
+alerts also drops native sensor pending runs and their recorded identity, and
+the stale-map sweep drops identity whose run is no longer pending. As for every
+host metric, `CheckHost` reads policy at the start of a report (the sensor's
+own threshold separately from the host gates, delay and intent policy during
+evaluation), so a report in flight during a save can act on the old policy.
+The next report corrects a sensor threshold or host gate; if the save turned
+global alerting off, `CheckHost` returns early and the stale-policy alert
+remains until alerting is on again or the stale sweep resolves it. Overrides are
+keyed by the reporting host ID and are not migrated when a host's identity is
+healed to a new ID, as for agent filesystem overrides; the threshold must be
+set again. The alert belongs to the host for history; operator intent, like
+the other host child alerts, still resolves under the child ID. Tests in
+`internal/alerts/operational_contract_test.go`
+(`TestHostNativeSensorResourceIDIsCollisionFree`,
+`TestHostNativeSensorThresholdRaisesOnlyFromItsOwnOverride`,
+`TestHostNativeSensorGapsHoldAndPolicyResolves`,
+`TestHostNativeSensorConfigSaveKeepsAlertItsOverrideStillHolds`,
+`TestHostNativeSensorPendingRunRestartsAfterPolicyOff`,
+`TestHostNativeSensorUsesSensorDelayPolicy`) and
+`TestResourceAlertSpecValidateAllowsAgentSensorMigrationBridgeType` pin this.
+No Thresholds UI writes these overrides yet.
+
### Agent custom sensors use canonical health-assessment alerts
Typed `HostSensorSummary.Custom` numeric, boolean, or timestamp readings with
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index f1772ae7e9..3f8bf3dac4 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -7231,8 +7231,9 @@ owner whose durable ID they carry (`historySubResourceOwner`): ZFS pool and
device alerts (`<storage ID>/zfs-pool:<pool>[/device:<device>]`) to the
storage, the Unraid array alert (`agent:<host ID>/storage:unraid-array`) to
the array storage with that agent source ID, and host filesystem, SMART disk,
-disk temperature, RAID and custom-sensor alerts (`agent:<host ID>/disk:`,
-`/disk_temp:`, `/raid:`, `/custom:`) to the host. The owner reference must
+disk temperature, RAID, custom-sensor and native-sensor alerts
+(`agent:<host ID>/disk:`, `/disk_temp:`, `/raid:`, `/custom:`, `/sensor:`) to
+the host. The owner reference must
resolve to exactly one resource of the expected type; an ambiguous or
incompatible owner is a conflict, so the event keeps its own reference,
follows no retained binding and is retried. Pool, mount and kernel device labels are names,
diff --git a/internal/ai/patrol_alerts_review_test.go b/internal/ai/patrol_alerts_review_test.go
index a672b4eb71..05b00d1f45 100644
--- a/internal/ai/patrol_alerts_review_test.go
+++ b/internal/ai/patrol_alerts_review_test.go
@@ -416,3 +416,32 @@ func TestGetResourceCurrentState_PresentChildSubjectIsNotRemoved(t *testing.T) {
}
}
}
+
+func TestPatrolReviewNeverResolvesNativeSensorAlerts(t *testing.T) {
+ now := time.Now().UTC()
+ ps := NewPatrolService(nil, nil)
+ resolver := &stubAlertResolver{alerts: []AlertInfo{{
+ ID: "sensor-alert",
+ Type: "temperature",
+ ResourceID: "agent:host-1/sensor:6170706c65736d632d6973612d303330302f74656d7031",
+ ResourceType: "agent-sensor",
+ Threshold: 45,
+ Value: 47,
+ StartTime: now.Add(-2 * time.Hour),
+ }}}
+ ps.alertResolver = resolver
+ provider := &mockPatrolProvider{response: "ALERT 1: RESOLVE: the machine looks cool now"}
+ ps.aiService = &Service{provider: provider, cfg: &config.AIConfig{Enabled: true, PatrolModel: "mock:model"}}
+ snap := newPatrolRuntimeState(models.StateSnapshot{Hosts: []models.Host{{ID: "host-1", Hostname: "macbook-pve", Status: "online"}}})
+
+ resolved := ps.reviewAndResolveAlertsState(context.Background(), snap, true, "")
+ if provider.calls != 1 {
+ t.Fatalf("model review calls = %d, want the alert to reach review so the guard is exercised", provider.calls)
+ }
+ if resolved != 0 || len(resolver.clears) != 0 {
+ t.Fatalf("Patrol resolved a native sensor alert without that sensor's reading: resolved=%d clears=%v", resolved, resolver.clears)
+ }
+ if !isNativeSensorAlertResource(" agent:host-1/sensor:00 ") || isNativeSensorAlertResource("agent:host-1/custom:fan") || isNativeSensorAlertResource("agent:host-1") || isNativeSensorAlertResource("node:sensor:00") {
+ t.Fatal("native sensor alert resource matching is wrong")
+ }
+}
diff --git a/internal/ai/patrol_run.go b/internal/ai/patrol_run.go
index ed487911f8..27afbfcd81 100644
--- a/internal/ai/patrol_run.go
+++ b/internal/ai/patrol_run.go
@@ -2924,6 +2924,13 @@ func (p *PatrolService) reviewAlertBatchState(ctx context.Context, batch []Alert
// guest measurement. Missing/stale/cache-inclusive memory cannot prove a
// memory alert recovered, even if the model asks to resolve it.
for i, alert := range batch {
+ // The snapshot carries no native sensor readings, so nothing in it
+ // can show that one sensor's temperature recovered.
+ if isNativeSensorAlertResource(alert.ResourceID) {
+ verdicts[i].resolve = false
+ verdicts[i].reason = ""
+ continue
+ }
if alert.Type != "memory" {
continue
}
@@ -2937,6 +2944,17 @@ func (p *PatrolService) reviewAlertBatchState(ctx context.Context, batch []Alert
return verdicts
}
+// isNativeSensorAlertResource reports whether an alert names one native
+// sensor of a host agent ("agent:<host>/sensor:<hex>").
+func isNativeSensorAlertResource(resourceID string) bool {
+ rest, ok := strings.CutPrefix(strings.TrimSpace(resourceID), "agent:")
+ if !ok {
+ return false
+ }
+ _, child, ok := strings.Cut(rest, "/")
+ return ok && strings.HasPrefix(child, "sensor:")
+}
+
// buildAlertReviewPromptState formats the batched alert-review prompt: one
// numbered section per alert with its trigger details and current resource
// state, plus strict per-line verdict output instructions. The current
diff --git a/internal/alerts/active_cleanup.go b/internal/alerts/active_cleanup.go
index 6c4ac58bd5..9559c904c9 100644
--- a/internal/alerts/active_cleanup.go
+++ b/internal/alerts/active_cleanup.go
@@ -346,7 +346,7 @@ func (m *Manager) CleanupAlertsForNodes(existingNodes map[string]bool) {
// ClearActiveAlerts removes all active and pending alerts, resetting the manager state.
func (m *Manager) ClearActiveAlerts() {
m.mu.Lock()
- if len(m.activeAlerts) == 0 && len(m.intentPending) == 0 && len(m.smartCounterSnapshots) == 0 && len(m.hostDiskTempPendingContexts) == 0 {
+ if len(m.activeAlerts) == 0 && len(m.intentPending) == 0 && len(m.smartCounterSnapshots) == 0 && len(m.hostDiskTempPendingContexts) == 0 && len(m.hostNativeSensorPendingCtx) == 0 {
m.mu.Unlock()
return
}
@@ -357,6 +357,7 @@ func (m *Manager) ClearActiveAlerts() {
state.Reset()
}
m.hostDiskTempPendingContexts = nil
+ m.hostNativeSensorPendingCtx = nil
m.intentPending = make(map[string]IntentPendingState)
m.intentRuntimeTicks = make(map[string]time.Duration)
m.recentAlerts = make(map[string]*Alert)
diff --git a/internal/alerts/canonical_metric.go b/internal/alerts/canonical_metric.go
index d1d5bf40ff..c82d80a12e 100644
--- a/internal/alerts/canonical_metric.go
+++ b/internal/alerts/canonical_metric.go
@@ -35,6 +35,8 @@ func resourceTypeLabel(resourceType string) string {
return "Application container"
case "agent-disk":
return "Disk"
+ case "agent-sensor":
+ return "Sensor"
case "agent":
return "Agent"
case "node":
diff --git a/internal/alerts/config_runtime.go b/internal/alerts/config_runtime.go
index d3376f0487..60ddfd8a18 100644
--- a/internal/alerts/config_runtime.go
+++ b/internal/alerts/config_runtime.go
@@ -132,6 +132,9 @@ func (m *Manager) updateConfigLocked(config AlertConfig) {
if m.reevaluateHostDiskTemperaturePendingNoLock() {
m.saveActiveAlertsAsync("disk temperature pending policy disabled")
}
+ if m.reevaluateHostNativeSensorPendingNoLock() {
+ m.saveActiveAlertsAsync("native sensor pending policy removed")
+ }
// Re-evaluate active alerts against new thresholds
m.reevaluateActiveAlertsLocked()
diff --git a/internal/alerts/host.go b/internal/alerts/host.go
index 266435da81..32ed5bb5f1 100644
--- a/internal/alerts/host.go
+++ b/internal/alerts/host.go
@@ -179,6 +179,12 @@ func (m *Manager) resolveHostAlertThresholdsNoLock(alert *Alert, resourceID stri
thresholds.DiskTemperature = m.lowestHostDiskTemperatureThresholdNoLock(thresholds.DiskTemperature)
}
}
+ // A native sensor alert is judged by its own override's temperature alone,
+ // as CheckHost judges it, never by the host's or a linked node's CPU
+ // temperature threshold. A removed or disabled override resolves it.
+ if alert != nil && isHostNativeSensorResourceID(resourceID) {
+ thresholds.Temperature = m.hostNativeSensorThresholdNoLock(strings.TrimSpace(resourceID))
+ }
// A filesystem alert is judged by the threshold CheckHost evaluates that
// filesystem against, so a config save does not resolve an alert its
// override or per-type fill threshold still holds. A disabled filesystem
@@ -343,6 +349,7 @@ func (m *Manager) CheckHost(host models.Host) {
m.clearHostRAIDAlerts(host.ID)
m.clearHostUnraidAlerts(host.ID)
m.clearHostCustomSensorAlerts(host.ID)
+ m.clearHostNativeSensorAlerts(host.ID)
return
}
@@ -353,6 +360,7 @@ func (m *Manager) CheckHost(host models.Host) {
m.clearHostRAIDAlerts(host.ID)
m.clearHostUnraidAlerts(host.ID)
m.clearHostCustomSensorAlerts(host.ID)
+ m.clearHostNativeSensorAlerts(host.ID)
return
}
@@ -386,6 +394,7 @@ func (m *Manager) CheckHost(host models.Host) {
baseMetadata["tags"] = append([]string(nil), host.Tags...)
}
m.syncHostCustomSensorAlerts(host, nodeName, instanceName, baseMetadata)
+ m.syncHostNativeSensorAlerts(host, nodeName, instanceName, baseMetadata)
cpuEvaluated := false
if thresholds.CPU != nil {
@@ -815,6 +824,7 @@ func (m *Manager) HandleHostRemoved(host models.Host) {
m.clearHostRAIDAlerts(host.ID)
m.clearHostUnraidAlerts(host.ID)
m.clearHostCustomSensorAlerts(host.ID)
+ m.clearHostNativeSensorAlerts(host.ID)
// No later report will close the host's pending disk temperature runs or
// reset its disk absence counts.
m.clearHostDiskTemperatureAlerts(host.ID)
@@ -831,6 +841,7 @@ func (m *Manager) HandleHostTelemetryExpired(host models.Host) {
// Expiry interrupts timing, not the separate connectivity confirmation.
m.interruptHostDiskTemperatureRuns(host.ID)
+ m.interruptHostNativeSensorRuns(host.ID)
m.resetHostSMARTDiskAbsences(host.ID)
if host.Unraid != nil {
@@ -855,6 +866,7 @@ func (m *Manager) HandleHostTelemetryExpired(host models.Host) {
m.clearHostRAIDAlerts(host.ID)
m.clearHostUnraidAlerts(host.ID)
m.clearHostCustomSensorAlerts(host.ID)
+ m.clearHostNativeSensorAlerts(host.ID)
return
}
m.clearHostCustomSensorAlerts(host.ID)
@@ -1031,6 +1043,7 @@ func (m *Manager) HandleHostOfflineWithCorrelation(host models.Host, correlation
diskResourcePrefixes := []string{
fmt.Sprintf("%s/disk:", resourceKey),
hostDiskTemperatureResourcePrefix(host.ID),
+ hostNativeSensorResourcePrefix(host.ID),
}
raidAlertPrefix := fmt.Sprintf("host-%s-raid-", host.ID)
var alertsToClear []string
diff --git a/internal/alerts/host_native_sensor.go b/internal/alerts/host_native_sensor.go
new file mode 100644
index 0000000000..eb417ac7bf
--- /dev/null
+++ b/internal/alerts/host_native_sensor.go
@@ -0,0 +1,295 @@
+package alerts
+
+import (
+ "encoding/hex"
+ "fmt"
+ "sort"
+ "strings"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts/reducer"
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
+ agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
+ "github.com/rs/zerolog/log"
+)
+
+// hostNativeSensorMetric is the metric a native temperature sensor's
+// threshold judges. It shares the temperature formatting, stability delay and
+// quiet-hours category, while its resource ID keeps it apart from the node
+// CPU temperature alert.
+const hostNativeSensorMetric = "temperature"
+
+func hostNativeSensorResourcePrefix(hostID string) string {
+ return hostResourceID(hostID) + "/sensor:"
+}
+
+// HostNativeSensorResourceID is the alert resource ID of one native sensor:
+// "agent:<host ID>/sensor:<lower-case hex of the sensor ID's UTF-8 bytes>".
+// The sensor ID ("<chip>/<channel>") can differ from another only by case or
+// punctuation, and host child IDs and metric names are lower-cased elsewhere,
+// so the hex form is the collision-free key its threshold override and alert
+// are stored under.
+func HostNativeSensorResourceID(hostID, sensorID string) string {
+ return hostNativeSensorResourcePrefix(hostID) + hex.EncodeToString([]byte(sensorID))
+}
+
+// isHostNativeSensorResourceID reports whether resourceID names one native
+// sensor of a host agent.
+func isHostNativeSensorResourceID(resourceID string) bool {
+ _, child, ok := strings.Cut(stripHostResourcePrefix(resourceID), "/")
+ return ok && strings.HasPrefix(child, "sensor:")
+}
+
+// hostNativeSensorThresholdNoLock is the threshold a native sensor is judged
+// by: its own override's temperature, and nothing else. A sensor has no
+// default and inherits no host, linked-node or CPU temperature threshold, so
+// a missing, disabled or zero override means it raises nothing. The result
+// is an owned copy. Callers must hold m.mu.
+func (m *Manager) hostNativeSensorThresholdNoLock(resourceID string) *HysteresisThreshold {
+ override, ok := m.config.Overrides[resourceID]
+ if !ok || override.Disabled || override.Temperature == nil || override.Temperature.Trigger <= 0 {
+ return nil
+ }
+ return ensureHysteresisThreshold(cloneThreshold(override.Temperature))
+}
+
+// hostNativeSensorTrackedResourcesNoLock lists the host's native sensor
+// resources that hold evaluator state: an active alert, a pending reducer
+// run, pending intent or a configured override. Cleanup walks this set, so
+// removing an override still reaches the run it started. Callers must hold
+// m.mu.
+func (m *Manager) hostNativeSensorTrackedResourcesNoLock(hostID string) map[string]struct{} {
+ prefix := hostNativeSensorResourcePrefix(hostID)
+ resources := make(map[string]struct{})
+ add := func(resourceID string) {
+ if strings.HasPrefix(resourceID, prefix) {
+ resources[resourceID] = struct{}{}
+ }
+ }
+ for resourceID := range m.config.Overrides {
+ add(resourceID)
+ }
+ for _, alert := range m.activeAlerts {
+ if alert != nil {
+ add(alert.ResourceID)
+ }
+ }
+ for _, state := range m.mirrorStatesNoLock() {
+ for _, resourceID := range state.PendingResourceIDs() {
+ add(resourceID)
+ }
+ }
+ for _, pending := range m.intentPending {
+ add(pending.ResourceID)
+ }
+ return resources
+}
+
+// hostNativeSensorContext is the host link identity a pending native sensor
+// run was started under, so a configuration save can re-resolve the host's
+// policy without another telemetry cache.
+type hostNativeSensorContext struct {
+ hostID, linkedNodeID, linkedVMID, linkedContainerID string
+}
+
+func (m *Manager) hostNativeSensorPendingNoLock(resourceID string) bool {
+ specID := canonicalMetricSpecID(resourceID, hostNativeSensorMetric)
+ for _, state := range m.mirrorStatesNoLock() {
+ if incident, ok := state.Incident(resourceID, specID); ok && incident.State == reducer.StatePending {
+ return true
+ }
+ }
+ _, pending := m.intentPending[canonicalMetricStateID(resourceID, hostNativeSensorMetric)]
+ return pending
+}
+
+// rememberHostNativeSensorPending keeps the host link identity of a live
+// pending run, and forgets it once the run is no longer pending.
+func (m *Manager) rememberHostNativeSensorPending(host models.Host, resourceID string) {
+ m.mu.Lock()
+ defer m.mu.Unlock()
+ if !m.hostNativeSensorPendingNoLock(resourceID) {
+ delete(m.hostNativeSensorPendingCtx, resourceID)
+ return
+ }
+ if m.hostNativeSensorPendingCtx == nil {
+ m.hostNativeSensorPendingCtx = make(map[string]hostNativeSensorContext)
+ }
+ m.hostNativeSensorPendingCtx[resourceID] = hostNativeSensorContext{host.ID, host.LinkedNodeID, host.LinkedVMID, host.LinkedContainerID}
+}
+
+func (m *Manager) interruptHostNativeSensorRunNoLock(resourceID string) bool {
+ delete(m.hostNativeSensorPendingCtx, resourceID)
+ return m.interruptMetricRunNoLock(resourceID, canonicalMetricSpecID(resourceID, hostNativeSensorMetric), canonicalMetricStateID(resourceID, hostNativeSensorMetric))
+}
+
+// clearHostNativeSensorResourceNoLock resolves a native sensor's alert and
+// drops its pending run. Callers must hold m.mu.
+func (m *Manager) clearHostNativeSensorResourceNoLock(resourceID string) bool {
+ changed := m.interruptHostNativeSensorRunNoLock(resourceID)
+ m.core.DropPendingForResource(resourceID)
+ for storageKey, alert := range m.activeAlerts {
+ if alert != nil && alert.ResourceID == resourceID {
+ m.clearAlertNoLock(storageKey)
+ changed = true
+ }
+ }
+ return changed
+}
+
+// clearHostNativeSensorAlerts resolves every native sensor alert of a host
+// and drops their pending runs: the host was removed, or its alerting was
+// switched off, so no later reading will resolve them.
+func (m *Manager) clearHostNativeSensorAlerts(hostID string) {
+ if strings.TrimSpace(hostID) == "" {
+ return
+ }
+ m.mu.Lock()
+ changed := false
+ for resourceID := range m.hostNativeSensorTrackedResourcesNoLock(hostID) {
+ changed = m.clearHostNativeSensorResourceNoLock(resourceID) || changed
+ }
+ m.mu.Unlock()
+ if changed {
+ m.saveActiveAlertsAsync("host native sensor alerts cleared")
+ }
+}
+
+// interruptHostNativeSensorRuns restarts timing for every native sensor of a
+// host without resolving a firing alert: its readings stopped arriving.
+func (m *Manager) interruptHostNativeSensorRuns(hostID string) {
+ if strings.TrimSpace(hostID) == "" {
+ return
+ }
+ m.mu.Lock()
+ changed := false
+ for resourceID := range m.hostNativeSensorTrackedResourcesNoLock(hostID) {
+ changed = m.interruptHostNativeSensorRunNoLock(resourceID) || changed
+ }
+ m.mu.Unlock()
+ if changed {
+ m.saveActiveAlertsAsync("host native sensor observation gap")
+ }
+}
+
+// syncHostNativeSensorAlerts judges each native temperature sensor that has
+// its own threshold override. A usable reading is evaluated on the canonical
+// metric path. An invalid reading, a reading without a value, or a configured
+// sensor missing from the report interrupts the run and holds any firing
+// alert: the inventory carries no completeness state, so absence is not
+// evidence that the sensor left. Removing or disabling the override resolves
+// the alert. CheckHost calls this only while the host's alerting is on.
+func (m *Manager) syncHostNativeSensorAlerts(host models.Host, nodeName, instanceName string, baseMetadata map[string]interface{}) {
+ reported := make(map[string]models.HostNativeSensor, len(host.Sensors.Native))
+ for _, sensor := range host.Sensors.Native {
+ if sensor.Kind != agentshost.NativeSensorKindTemperature || sensor.ID == "" {
+ continue
+ }
+ resourceID := HostNativeSensorResourceID(host.ID, sensor.ID)
+ if _, duplicate := reported[resourceID]; !duplicate {
+ reported[resourceID] = sensor
+ }
+ }
+
+ m.mu.Lock()
+ tracked := m.hostNativeSensorTrackedResourcesNoLock(host.ID)
+ thresholds := make(map[string]*HysteresisThreshold, len(tracked))
+ changed := false
+ for resourceID := range tracked {
+ if threshold := m.hostNativeSensorThresholdNoLock(resourceID); threshold != nil {
+ thresholds[resourceID] = threshold
+ continue
+ }
+ changed = m.clearHostNativeSensorResourceNoLock(resourceID) || changed
+ }
+ m.mu.Unlock()
+ if changed {
+ m.saveActiveAlertsAsync("host native sensor threshold removed")
+ }
+
+ resourceIDs := make([]string, 0, len(thresholds))
+ for resourceID := range thresholds {
+ resourceIDs = append(resourceIDs, resourceID)
+ }
+ sort.Strings(resourceIDs)
+ for _, resourceID := range resourceIDs {
+ threshold := thresholds[resourceID]
+ sensor, present := reported[resourceID]
+ if !present || sensor.Status != agentshost.NativeSensorStatusOK || sensor.Value == nil {
+ m.mu.Lock()
+ interrupted := m.interruptHostNativeSensorRunNoLock(resourceID)
+ m.mu.Unlock()
+ if interrupted {
+ m.saveActiveAlertsAsync("host native sensor observation gap")
+ }
+ continue
+ }
+
+ label := strings.TrimSpace(sensor.Label)
+ if label == "" {
+ label = sensor.ID
+ }
+ resourceName := fmt.Sprintf("%s (%s)", hostDisplayName(host), label)
+ metadata := hostChildAlertMetadata(baseMetadata, hostSensorAlertResourceType)
+ metadata["metric"] = hostNativeSensorMetric
+ metadata["sensorId"] = sensor.ID
+ metadata["sensorChip"] = sensor.Chip
+ metadata["sensorChannel"] = sensor.Channel
+ metadata["sensorLabel"] = sensor.Label
+ metadata["temperature"] = *sensor.Value
+
+ spec, err := buildCanonicalMetricSpec(resourceID, resourceName, unifiedresources.ResourceType(hostSensorAlertResourceType), hostNativeSensorMetric, threshold)
+ if err != nil {
+ log.Warn().
+ Err(err).
+ Str("resourceID", resourceID).
+ Str("host", hostDisplayName(host)).
+ Str("sensor", sensor.ID).
+ Msg("Skipping invalid canonical host native sensor metric spec")
+ m.mu.Lock()
+ m.interruptHostNativeSensorRunNoLock(resourceID)
+ m.mu.Unlock()
+ continue
+ }
+ message := fmt.Sprintf("%s temperature at %s", label, formatMetricValue(*sensor.Value, "°C"))
+ m.checkMetricWithCanonicalSpec(spec, resourceName, nodeName, instanceName, hostSensorAlertResourceType, *sensor.Value, threshold, &metricOptions{Metadata: metadata, Message: message})
+ m.rememberHostNativeSensorPending(host, resourceID)
+ }
+}
+
+// reevaluateHostNativeSensorPendingNoLock drops the pending evidence of every
+// native sensor whose policy a configuration save switched off: its own
+// threshold, the host's (or an inherited linked resource's) Disabled, all
+// agents' alerting or global alerting. Disabling and re-enabling between
+// reports therefore cannot reuse the earlier grace. A run restored without
+// its host link identity is interrupted, since the save cannot be judged
+// against it. A firing alert is re-judged by the config-save resolver instead.
+// Callers must hold m.mu.
+func (m *Manager) reevaluateHostNativeSensorPendingNoLock() bool {
+ changed := false
+ resources := make(map[string]struct{})
+ for _, state := range m.mirrorStatesNoLock() {
+ for _, resourceID := range state.PendingResourceIDs() {
+ resources[resourceID] = struct{}{}
+ }
+ }
+ for _, pending := range m.intentPending {
+ resources[pending.ResourceID] = struct{}{}
+ }
+ for resourceID := range m.hostNativeSensorPendingCtx {
+ resources[resourceID] = struct{}{}
+ }
+ allDisabled, _ := m.alertPolicyTypeSwitchesNoLock("agent")
+ for resourceID := range resources {
+ if !isHostNativeSensorResourceID(resourceID) || !m.hostNativeSensorPendingNoLock(resourceID) {
+ delete(m.hostNativeSensorPendingCtx, resourceID)
+ continue
+ }
+ ctx, known := m.hostNativeSensorPendingCtx[resourceID]
+ if !known || !m.config.Enabled || allDisabled || m.hostNativeSensorThresholdNoLock(resourceID) == nil ||
+ m.resolveHostThresholdsNoLock(ctx.hostID, ctx.linkedNodeID, ctx.linkedVMID, ctx.linkedContainerID).Disabled {
+ changed = m.interruptHostNativeSensorRunNoLock(resourceID) || changed
+ }
+ }
+ return changed
+}
diff --git a/internal/alerts/manager.go b/internal/alerts/manager.go
index f3339a9845..7218a8bfaf 100644
--- a/internal/alerts/manager.go
+++ b/internal/alerts/manager.go
@@ -75,14 +75,15 @@ type Manager struct {
// through evaluateCanonicalLifecycleAlert and the poll-driven recovery
// paths (docs/ALERT_ENGINE_EVOLUTION.md, Phase 2). Access under m.mu.
core *reducer.State
- unifiedIncidentConfirmations map[string]int // Track consecutive provider-incident observations before activation
- unifiedIncidentFirstSeen map[string]time.Time // Preserve the first confirmed observation as lifecycle start
- unifiedIncidentRecoveries map[string]int // Track consecutive healthy observations before provider-incident recovery
- hostDiskTempPendingContexts map[string]hostDiskTempContext // Only live pending temperature runs; config saves need link/type identity
- hostSMARTRiskAbsences map[string]int // Consecutive non-empty reports omitting a SMART risk resource
- hostDiskTempAbsences map[string]int // Track consecutive SMART reports missing a disk that holds temperature alert state
- dockerRestartTracking map[string]*dockerRestartRecord // Track restart counts and times for restart loop detection
- dockerUpdateFirstSeen map[string]time.Time // Track when image updates were first detected for alert delay
+ unifiedIncidentConfirmations map[string]int // Track consecutive provider-incident observations before activation
+ unifiedIncidentFirstSeen map[string]time.Time // Preserve the first confirmed observation as lifecycle start
+ unifiedIncidentRecoveries map[string]int // Track consecutive healthy observations before provider-incident recovery
+ hostDiskTempPendingContexts map[string]hostDiskTempContext // Only live pending temperature runs; config saves need link/type identity
+ hostNativeSensorPendingCtx map[string]hostNativeSensorContext // Only live pending native sensor runs; config saves need the host's link identity
+ hostSMARTRiskAbsences map[string]int // Consecutive non-empty reports omitting a SMART risk resource
+ hostDiskTempAbsences map[string]int // Track consecutive SMART reports missing a disk that holds temperature alert state
+ dockerRestartTracking map[string]*dockerRestartRecord // Track restart counts and times for restart loop detection
+ dockerUpdateFirstSeen map[string]time.Time // Track when image updates were first detected for alert delay
// Stable identity tracking prevents update-delay resets when host IDs churn.
dockerUpdateFirstSeenByIdentity map[string]time.Time
dockerUpdateLastObserved map[string]time.Time // Resource and stable identity keys; activity, not pending age.
diff --git a/internal/alerts/operational_contract_test.go b/internal/alerts/operational_contract_test.go
index 2d6bccd7bf..5fa8c61a11 100644
--- a/internal/alerts/operational_contract_test.go
+++ b/internal/alerts/operational_contract_test.go
@@ -1076,3 +1076,250 @@ func TestHistoryOutputKeepsTheRecordAndOnlyTheNewestEvidence(t *testing.T) {
t.Fatalf("shaping history output changed its input alert to %d envelopes", len(alert.Evidence))
}
}
+
+func nativeSensorManager(t *testing.T) *Manager {
+ t.Helper()
+ m, _ := continuityManager(t, false)
+ m.mu.Lock()
+ m.config.MetricTimeThresholds = map[string]map[string]int{"all": {"temperature": 0}}
+ m.mu.Unlock()
+ return m
+}
+
+func nativeSensorHost(value *float64, status string) models.Host {
+ return models.Host{ID: "host-mbp", Hostname: "macbook-pve", Status: "online", LinkedNodeID: "node-mbp",
+ Sensors: models.HostSensorSummary{Native: []models.HostNativeSensor{
+ {ID: "applesmc-isa-0300/temp1", Chip: "applesmc-isa-0300", Channel: "temp1", Label: "TB0T", Kind: "temperature", Unit: "celsius", Value: value, Status: status},
+ // Differs from TB0T's ID only by case after the channel; must stay its own resource.
+ {ID: "applesmc-isa-0300/temp2", Chip: "applesmc-isa-0300", Channel: "temp2", Label: "TC1f", Kind: "temperature", Unit: "celsius", Value: value, Status: status},
+ }}}
+}
+
+func nativeSensorAlerts(m *Manager) []Alert {
+ var out []Alert
+ for _, alert := range m.GetActiveAlerts() {
+ if isHostNativeSensorResourceID(alert.ResourceID) {
+ out = append(out, alert)
+ }
+ }
+ return out
+}
+
+func TestHostNativeSensorResourceIDIsCollisionFree(t *testing.T) {
+ // Lower-case hex of the UTF-8 bytes: case, punctuation and non-ASCII
+ // differences survive, and the key carries no '/' or ':'.
+ for sensorID, want := range map[string]string{
+ "applesmc-isa-0300/temp1": "agent:h/sensor:6170706c65736d632d6973612d303330302f74656d7031",
+ "A/temp1": "agent:h/sensor:412f74656d7031",
+ "a/temp1": "agent:h/sensor:612f74656d7031",
+ "é/temp1": "agent:h/sensor:c3a92f74656d7031",
+ } {
+ if got := HostNativeSensorResourceID("h", sensorID); got != want {
+ t.Errorf("HostNativeSensorResourceID(%q) = %q, want %q", sensorID, got, want)
+ }
+ }
+ if !isHostNativeSensorResourceID("agent:h/sensor:00") || isHostNativeSensorResourceID("agent:h/custom:fan") || isHostNativeSensorResourceID("agent:h") {
+ t.Fatal("native sensor resource ID classification is wrong")
+ }
+}
+
+func TestHostNativeSensorThresholdRaisesOnlyFromItsOwnOverride(t *testing.T) {
+ m := nativeSensorManager(t)
+ hot := 47.0
+ host := nativeSensorHost(&hot, "ok")
+ battery := HostNativeSensorResourceID(host.ID, "applesmc-isa-0300/temp1")
+
+ // No override: no default, and neither the host's nor the linked node's
+ // CPU temperature threshold is inherited.
+ m.mu.Lock()
+ m.config.AgentDefaults.Temperature = &HysteresisThreshold{Trigger: 30, Clear: 25}
+ m.config.Overrides[host.LinkedNodeID] = ThresholdConfig{Temperature: &HysteresisThreshold{Trigger: 30, Clear: 25}}
+ m.mu.Unlock()
+ m.CheckHost(host)
+ if alerts := nativeSensorAlerts(m); len(alerts) != 0 {
+ t.Fatalf("sensor without its own override raised %+v", alerts)
+ }
+
+ m.mu.Lock()
+ m.config.Overrides[battery] = ThresholdConfig{Temperature: &HysteresisThreshold{Trigger: 45, Clear: 40}}
+ m.mu.Unlock()
+ m.CheckHost(host)
+ alerts := nativeSensorAlerts(m)
+ if len(alerts) != 1 {
+ t.Fatalf("battery override raised %d sensor alerts, want exactly the battery's", len(alerts))
+ }
+ alert := alerts[0]
+ if alert.ResourceID != battery || alert.Type != "temperature" || alert.ID != battery+"::metric-threshold:temperature" ||
+ alert.Value != hot || alert.Threshold != 45 || alert.ResourceName != "macbook-pve (Host Agent) (TB0T)" ||
+ alert.Message != "TB0T temperature at 47.0°C" {
+ t.Fatalf("battery alert = %+v", alert)
+ }
+ if alert.Metadata["sensorId"] != "applesmc-isa-0300/temp1" || alert.Metadata["sensorLabel"] != "TB0T" || alert.Metadata["resourceType"] != "agent-sensor" {
+ t.Fatalf("battery alert metadata = %+v", alert.Metadata)
+ }
+
+ cool := 38.0
+ m.CheckHost(nativeSensorHost(&cool, "ok"))
+ if alerts := nativeSensorAlerts(m); len(alerts) != 0 {
+ t.Fatalf("reading below the clear value kept %+v", alerts)
+ }
+}
+
+func TestHostNativeSensorGapsHoldAndPolicyResolves(t *testing.T) {
+ hot := 47.0
+ for _, gap := range []string{"invalid", "no-value", "missing", "empty-inventory", "expired"} {
+ for _, policy := range []string{"override-removed", "override-disabled", "override-zero", "config-save", "host-disabled", "agents-disabled", "host-removed"} {
+ t.Run(gap+"/"+policy, func(t *testing.T) {
+ m := nativeSensorManager(t)
+ host := nativeSensorHost(&hot, "ok")
+ battery := HostNativeSensorResourceID(host.ID, "applesmc-isa-0300/temp1")
+ m.mu.Lock()
+ m.config.Overrides[battery] = ThresholdConfig{Temperature: &HysteresisThreshold{Trigger: 45, Clear: 40}}
+ m.mu.Unlock()
+ m.CheckHost(host)
+ if len(nativeSensorAlerts(m)) != 1 {
+ t.Fatal("control must fire")
+ }
+
+ gapped := nativeSensorHost(&hot, "ok")
+ switch gap {
+ case "invalid":
+ unattached := -127.0
+ gapped = nativeSensorHost(&unattached, "invalid")
+ case "no-value":
+ gapped = nativeSensorHost(nil, "invalid")
+ case "missing":
+ gapped.Sensors.Native = gapped.Sensors.Native[1:]
+ case "empty-inventory":
+ gapped.Sensors.Native = nil
+ }
+ if gap == "expired" {
+ m.HandleHostTelemetryExpired(host)
+ } else {
+ m.CheckHost(gapped)
+ }
+ if alerts := nativeSensorAlerts(m); len(alerts) != 1 || alerts[0].ResourceID != battery {
+ t.Fatalf("a %s reading resolved or duplicated the held alert: %+v", gap, alerts)
+ }
+
+ switch policy {
+ case "config-save":
+ cfg := m.GetConfig()
+ delete(cfg.Overrides, battery)
+ m.UpdateConfig(cfg)
+ case "host-removed":
+ m.HandleHostRemoved(gapped)
+ default:
+ m.mu.Lock()
+ switch policy {
+ case "override-removed":
+ delete(m.config.Overrides, battery)
+ case "override-disabled":
+ m.config.Overrides[battery] = ThresholdConfig{Disabled: true, Temperature: &HysteresisThreshold{Trigger: 45, Clear: 40}}
+ case "override-zero":
+ m.config.Overrides[battery] = ThresholdConfig{Temperature: &HysteresisThreshold{}}
+ case "host-disabled":
+ m.config.Overrides[host.ID] = ThresholdConfig{Disabled: true}
+ case "agents-disabled":
+ m.config.DisableAllAgents = true
+ }
+ m.mu.Unlock()
+ m.CheckHost(gapped)
+ }
+ if alerts := nativeSensorAlerts(m); len(alerts) != 0 {
+ t.Fatalf("%s left %+v", policy, alerts)
+ }
+ })
+ }
+ }
+}
+
+func TestHostNativeSensorConfigSaveKeepsAlertItsOverrideStillHolds(t *testing.T) {
+ m := nativeSensorManager(t)
+ hot := 47.0
+ host := nativeSensorHost(&hot, "ok")
+ battery := HostNativeSensorResourceID(host.ID, "applesmc-isa-0300/temp1")
+ m.mu.Lock()
+ m.config.Overrides[battery] = ThresholdConfig{Temperature: &HysteresisThreshold{Trigger: 45, Clear: 40}}
+ m.mu.Unlock()
+ m.CheckHost(host)
+ // Any save re-judges active alerts. The host has no CPU temperature
+ // threshold, so a resolver that read the host's would resolve this.
+ cfg := m.GetConfig()
+ cfg.AgentDefaults.Temperature = nil
+ m.UpdateConfig(cfg)
+ if alerts := nativeSensorAlerts(m); len(alerts) != 1 {
+ t.Fatalf("config save resolved a sensor alert its own override still holds: %+v", alerts)
+ }
+ if got := m.GetConfig().Overrides[battery].Temperature; got == nil || got.Trigger != 45 {
+ t.Fatalf("saved sensor override = %+v, want trigger 45 preserved", got)
+ }
+}
+
+func TestHostNativeSensorPendingRunRestartsAfterPolicyOff(t *testing.T) {
+ for _, policy := range []string{"override-removed", "host-disabled", "agents-disabled", "alerts-disabled", "alerts-cleared"} {
+ t.Run(policy, func(t *testing.T) {
+ m, elapsed := continuityManager(t, false)
+ hot := 47.0
+ host := nativeSensorHost(&hot, "ok")
+ battery := HostNativeSensorResourceID(host.ID, "applesmc-isa-0300/temp1")
+ setPolicy := func(on bool) {
+ cfg := m.GetConfig()
+ cfg.Overrides[battery] = ThresholdConfig{Temperature: &HysteresisThreshold{Trigger: 45, Clear: 40}}
+ switch policy {
+ case "override-removed":
+ if !on {
+ delete(cfg.Overrides, battery)
+ }
+ case "host-disabled":
+ if on {
+ delete(cfg.Overrides, host.ID)
+ } else {
+ cfg.Overrides[host.ID] = ThresholdConfig{Disabled: true}
+ }
+ case "agents-disabled":
+ cfg.DisableAllAgents = !on
+ case "alerts-disabled":
+ cfg.Enabled = on
+ }
+ m.UpdateConfig(cfg)
+ }
+ setPolicy(true)
+ m.CheckHost(host) // starts the 60s temperature grace
+ elapsed.Store(int64(40 * time.Second))
+ if policy == "alerts-cleared" {
+ m.ClearActiveAlerts()
+ } else {
+ setPolicy(false)
+ setPolicy(true)
+ }
+ elapsed.Store(int64(70 * time.Second))
+ m.CheckHost(host)
+ if alerts := nativeSensorAlerts(m); len(alerts) != 0 {
+ t.Fatalf("re-enabled sensor reused grace from before %s: %+v", policy, alerts)
+ }
+ elapsed.Store(int64(131 * time.Second))
+ m.CheckHost(host)
+ if alerts := nativeSensorAlerts(m); len(alerts) != 1 {
+ t.Fatalf("sustained reading after re-enable did not fire: %+v", alerts)
+ }
+ })
+ }
+}
+
+func TestHostNativeSensorUsesSensorDelayPolicy(t *testing.T) {
+ m, _ := continuityManager(t, false)
+ hot := 47.0
+ host := nativeSensorHost(&hot, "ok")
+ battery := HostNativeSensorResourceID(host.ID, "applesmc-isa-0300/temp1")
+ cfg := m.GetConfig()
+ cfg.Overrides[battery] = ThresholdConfig{Temperature: &HysteresisThreshold{Trigger: 45, Clear: 40}}
+ // The agent-wide temperature delay stays 60s; a sensor-specific delay of
+ // zero must win for sensor alerts.
+ cfg.MetricTimeThresholds = map[string]map[string]int{"all": {"temperature": 60}, "agent-sensor": {"temperature": 0}}
+ m.UpdateConfig(cfg)
+ m.CheckHost(host)
+ if alerts := nativeSensorAlerts(m); len(alerts) != 1 {
+ t.Fatalf("sensor-specific zero delay was ignored: %+v", alerts)
+ }
+}
diff --git a/internal/alerts/specs/types.go b/internal/alerts/specs/types.go
index c2c0f5bb2b..fd656e846f 100644
--- a/internal/alerts/specs/types.go
+++ b/internal/alerts/specs/types.go
@@ -1080,11 +1080,13 @@ func isKnownResourceType(rt unifiedresources.ResourceType) bool {
if rt == "" {
return false
}
- // "node", "agent-disk", "docker-host", "backup-subject", "proxmox-disk", and
- // "connection" remain migration bridges while live alerts are still keyed
- // separately from the canonical unified resource model.
+ // "node", "agent-disk", "agent-sensor", "docker-host", "backup-subject",
+ // "proxmox-disk", and "connection" remain migration bridges while live
+ // alerts are still keyed separately from the canonical unified resource
+ // model.
if rt != unifiedresources.ResourceType("node") &&
rt != unifiedresources.ResourceType("agent-disk") &&
+ rt != unifiedresources.ResourceType("agent-sensor") &&
rt != unifiedresources.ResourceType("docker-host") &&
rt != unifiedresources.ResourceType("backup-subject") &&
rt != unifiedresources.ResourceType("proxmox-disk") &&
@@ -1096,6 +1098,7 @@ func isKnownResourceType(rt unifiedresources.ResourceType) bool {
case unifiedresources.ResourceTypeAgent,
unifiedresources.ResourceType("node"),
unifiedresources.ResourceType("agent-disk"),
+ unifiedresources.ResourceType("agent-sensor"),
unifiedresources.ResourceType("docker-host"),
unifiedresources.ResourceType("backup-subject"),
unifiedresources.ResourceType("proxmox-disk"),
diff --git a/internal/alerts/specs/types_test.go b/internal/alerts/specs/types_test.go
index 469d1f4638..d888b1d5b5 100644
--- a/internal/alerts/specs/types_test.go
+++ b/internal/alerts/specs/types_test.go
@@ -338,6 +338,27 @@ func TestResourceAlertSpecValidateAllowsAgentDiskMigrationBridgeType(t *testing.
}
}
+func TestResourceAlertSpecValidateAllowsAgentSensorMigrationBridgeType(t *testing.T) {
+ t.Parallel()
+
+ spec := ResourceAlertSpec{
+ ID: "agent:host1/sensor:6170706c65736d632d6973612d303330302f74656d7031::metric-threshold:temperature",
+ ResourceID: "agent:host1/sensor:6170706c65736d632d6973612d303330302f74656d7031",
+ ResourceType: unifiedresources.ResourceType("agent-sensor"),
+ Kind: AlertSpecKindMetricThreshold,
+ Severity: AlertSeverityWarning,
+ MetricThreshold: &MetricThresholdSpec{
+ Metric: "temperature",
+ Direction: ThresholdDirectionAbove,
+ Trigger: 45,
+ },
+ }
+
+ if err := spec.Validate(); err != nil {
+ t.Fatalf("Validate() error = %v", err)
+ }
+}
+
func TestResourceAlertSpecValidateAllowsDockerHostMigrationBridgeType(t *testing.T) {
t.Parallel()
diff --git a/internal/alerts/tracking_cleanup.go b/internal/alerts/tracking_cleanup.go
index 9e5882c2a1..094ad44fa7 100644
--- a/internal/alerts/tracking_cleanup.go
+++ b/internal/alerts/tracking_cleanup.go
@@ -34,6 +34,13 @@ func (m *Manager) cleanupStaleMaps() {
cleaned := 0
cleaned += m.core.PruneStalePending(now.Add(-staleThreshold))
+ // A native sensor's link identity is kept only while its run is pending.
+ for resourceID := range m.hostNativeSensorPendingCtx {
+ if !m.hostNativeSensorPendingNoLock(resourceID) {
+ delete(m.hostNativeSensorPendingCtx, resourceID)
+ cleaned++
+ }
+ }
for alertID, history := range m.flappingHistory {
if !m.hasActiveAlertNoLock(alertID) {
diff --git a/internal/unifiedresources/history_identity.go b/internal/unifiedresources/history_identity.go
index a37700bdc3..b18cc93233 100644
--- a/internal/unifiedresources/history_identity.go
+++ b/internal/unifiedresources/history_identity.go
@@ -212,7 +212,8 @@ func (rr *ResourceRegistry) dockerHistoryOwnerLocked(ref string) string {
// - "agent:<host ID>/storage:<array>" (Unraid array) is the agent source ID
// "<host ID>/storage:<array>" of the host's array storage.
// - "agent:<host ID>/disk:<mount or device>", ".../disk_temp:<device>",
-// ".../raid:<device>" and ".../custom:<sensor>" belong to the host.
+// ".../raid:<device>", ".../custom:<sensor>" and ".../sensor:<hex of a
+// native sensor ID>" belong to the host.
//
// Pool, mount and kernel device labels are names: a device name can belong to
// a different disk after a reboot, so these never bind a physical disk.
@@ -226,7 +227,7 @@ func historySubResourceOwner(ref string) (ownerRef string, ownerType ResourceTyp
switch kind {
case "storage":
return hostID + "/" + child, ResourceTypeStorage, true
- case "disk", "disk_temp", "raid", "custom":
+ case "disk", "disk_temp", "raid", "custom", "sensor":
return "agent:" + hostID, ResourceTypeAgent, true
}
return "", "", false
diff --git a/internal/unifiedresources/history_identity_test.go b/internal/unifiedresources/history_identity_test.go
index 1990091b71..f5eee4f62f 100644
--- a/internal/unifiedresources/history_identity_test.go
+++ b/internal/unifiedresources/history_identity_test.go
@@ -513,14 +513,15 @@ func TestHistoryIdentityMonitorAdapterResolvesSubResourceReferences(t *testing.T
require.NotEmpty(t, diskID)
bound := map[string]string{
- "lab-pve1-local-zfs/zfs-pool:local-zfs": storageID,
- "lab-pve1-local-zfs/zfs-pool:local-zfs/device:sda2": storageID,
- "agent:host-pve1/disk:var": nodeID,
- "agent:host-pve1/disk:sda": nodeID,
- "agent:host-pve1/disk_temp:sda": nodeID,
- "agent:host-pve1/raid:md0": nodeID,
- "agent:host-pve1/custom:fan1": nodeID,
- "agent:host-nas/storage:unraid-array": unraidID,
+ "lab-pve1-local-zfs/zfs-pool:local-zfs": storageID,
+ "lab-pve1-local-zfs/zfs-pool:local-zfs/device:sda2": storageID,
+ "agent:host-pve1/disk:var": nodeID,
+ "agent:host-pve1/disk:sda": nodeID,
+ "agent:host-pve1/disk_temp:sda": nodeID,
+ "agent:host-pve1/raid:md0": nodeID,
+ "agent:host-pve1/custom:fan1": nodeID,
+ "agent:host-pve1/sensor:6170706c65736d632d6973612d303330302f74656d7031": nodeID,
+ "agent:host-nas/storage:unraid-array": unraidID,
}
unbound := []string{
"lab-pve1/zfs-pool:local-zfs", // the owner part names a node, not a storage
@@ -528,6 +529,7 @@ func TestHistoryIdentityMonitorAdapterResolvesSubResourceReferences(t *testing.T
"agent:pve1/disk:var", // a hostname, not the host ID
"agent:host-pve1/service:sshd", // not a sub-resource shape any producer emits
"agent:host-pve1/disk:",
+ "agent:host-pve1/sensor:",
}
refs := append([]string{}, unbound...)
for ref := range bound {
@@ -975,8 +977,9 @@ func TestAlertResourceReferenceMarksComponentOwners(t *testing.T) {
"agent:host-src-1/disk_temp:sda": true,
"agent:host-src-1/raid:md0": true,
"agent:host-src-1/custom:fan": true,
- "docker:dh-7f3a": false,
- "docker:dh-7f3a/" + container: false,
+ "agent:host-src-1/sensor:636f726574656d702d6973612d303030302f74656d7031": true,
+ "docker:dh-7f3a": false,
+ "docker:dh-7f3a/" + container: false,
} {
binding, claimed := registry.ResolveAlertResourceReference(ref)
require.True(t, claimed, ref)