Files
Pulse/internal/unifiedresources/physical_disk_risk.go
rcourtman 3fd5411ecc Judge disk heat by the alert disk temperature thresholds
Pulse decided whether a physical disk was too hot in three places with
three thresholds. Disk risk added temperature_high at a flat 60/70C for
every disk type and drove the disk status and the Physical Disks Health
verdict. Patrol flagged anything over 55C and the AI chat context listed
disks from 50C. Alerts and the Temp column used the per-type thresholds
users tune in Alerts (NVMe 70, SAS 65, SATA 55 by default). An NVMe at
63C read Running Hot beside a green Temp cell. A SATA disk at 56C read
Healthy beside a red one. A user who raised the NVMe trigger to 75 still
got a hot verdict at 70.

The alert disk temperature policy now decides disk heat.
alerts.Manager.DiskTemperatureThreshold exposes the per-type resolution
CheckHost already applies.

- Disk risk no longer judges temperature. Every registry that rebuilds
  risk lacks the alert configuration, so no rule there could honour it.
  A hot disk keeps an online status.
- The Health verdict reads Running Hot when a current reading reaches
  the disk type's trigger. It uses the thresholds object that colours
  the Temp cell, so the two cannot disagree. The amber band below the
  trigger stays a cell colour, not a verdict.
- The TrueNAS storage table lost the heat it used to get from risk. It
  now judges heat the same way: an Attention row with the reason, and a
  warning dot for phones.
- Patrol triage, its disk issue filter, finding recovery and the chat
  context's attention list judge the collected reading against the same
  trigger, including scoped runs and a provider set before Patrol
  starts.
- A switched-off agent Disk Temp default resolves to no thresholds,
  which the displays that read them now treat as off.

Per-host Disk Temp overrides do not reach these surfaces yet. TrueNAS
disk alerts, the TrueNAS disk drawer and PDF reports keep their own
fixed temperatures for now.
2026-10-07 01:19:31 +01:00

155 lines
4.8 KiB
Go

package unifiedresources
import (
"strings"
"github.com/rcourtman/pulse-go-rewrite/internal/storagehealth"
)
func PhysicalDiskRiskFromAssessment(assessment storagehealth.Assessment) *PhysicalDiskRisk {
return PhysicalDiskRiskFromAssessmentAndIncidents(assessment, nil)
}
func PhysicalDiskRiskFromAssessmentAndIncidents(assessment storagehealth.Assessment, incidents []ResourceIncident) *PhysicalDiskRisk {
reasons := make([]PhysicalDiskRiskReason, 0, len(assessment.Reasons)+len(incidents))
seen := make(map[string]struct{}, len(assessment.Reasons)+len(incidents))
level := assessment.Level
for _, reason := range assessment.Reasons {
appendPhysicalDiskRiskReason(&reasons, seen, reason.Code, reason.Severity, reason.Summary)
if incidentSeverityRank(reason.Severity) > incidentSeverityRank(level) {
level = reason.Severity
}
}
for _, incident := range incidents {
if !physicalDiskIncidentAffectsRisk(incident) {
continue
}
appendPhysicalDiskRiskReason(&reasons, seen, incident.Code, incident.Severity, incident.Summary)
if incidentSeverityRank(incident.Severity) > incidentSeverityRank(level) {
level = incident.Severity
}
}
if level == storagehealth.RiskHealthy && len(reasons) == 0 {
return nil
}
return &PhysicalDiskRisk{
Level: level,
Reasons: reasons,
}
}
func appendPhysicalDiskRiskReason(reasons *[]PhysicalDiskRiskReason, seen map[string]struct{}, code string, severity storagehealth.RiskLevel, summary string) {
code = strings.TrimSpace(code)
summary = strings.TrimSpace(summary)
if code == "" || summary == "" {
return
}
key := code + "\x00" + summary
if _, ok := seen[key]; ok {
return
}
seen[key] = struct{}{}
*reasons = append(*reasons, PhysicalDiskRiskReason{
Code: code,
Severity: severity,
Summary: summary,
})
}
func physicalDiskIncidentAffectsRisk(incident ResourceIncident) bool {
resource := &Resource{Type: ResourceTypePhysicalDisk}
return IncidentCategoryForResource(resource, incident) == IncidentCategoryDiskHealth
}
func physicalDiskRiskFromMeta(meta *PhysicalDiskMeta, incidents []ResourceIncident) *PhysicalDiskRisk {
return PhysicalDiskRiskFromAssessmentAndIncidents(physicalDiskAssessmentFromMeta(meta), incidents)
}
func physicalDiskRiskFromAssessment(assessment storagehealth.Assessment) *PhysicalDiskRisk {
return PhysicalDiskRiskFromAssessmentAndIncidents(assessment, nil)
}
func physicalDiskAssessmentFromMeta(meta *PhysicalDiskMeta) storagehealth.Assessment {
if meta == nil {
return storagehealth.Assessment{Level: storagehealth.RiskHealthy}
}
sample := storagehealth.Sample{
Model: meta.Model,
Health: meta.Health,
Wearout: meta.Wearout,
WearoutKnown: storagehealth.WearoutReported(meta.Wearout, meta.DiskType),
}
if meta.SMART != nil {
if meta.SMART.PowerOnHours != nil {
sample.PowerOnHours = *meta.SMART.PowerOnHours
}
if meta.SMART.PowerCycles != nil {
sample.PowerCycles = *meta.SMART.PowerCycles
}
if meta.SMART.ReallocatedSectors != nil {
sample.ReallocatedSectors = *meta.SMART.ReallocatedSectors
}
if meta.SMART.PendingSectors != nil {
sample.PendingSectors = *meta.SMART.PendingSectors
}
if meta.SMART.OfflineUncorrectable != nil {
sample.OfflineUncorrectable = *meta.SMART.OfflineUncorrectable
}
if meta.SMART.UDMACRCErrors != nil {
sample.UDMACRCErrors = *meta.SMART.UDMACRCErrors
}
if meta.SMART.PercentageUsed != nil {
sample.PercentageUsed = *meta.SMART.PercentageUsed
if remaining := storagehealth.RemainingLifeFromPercentageUsed(*meta.SMART.PercentageUsed); remaining >= 0 {
sample.Wearout = remaining
sample.WearoutKnown = true
} else {
sample.Wearout = -1
sample.WearoutKnown = false
}
}
if meta.SMART.AvailableSpare != nil {
sample.AvailableSpare = *meta.SMART.AvailableSpare
sample.AvailableSpareKnown = true
}
if meta.SMART.MediaErrors != nil {
sample.MediaErrors = *meta.SMART.MediaErrors
}
if meta.SMART.UnsafeShutdowns != nil {
sample.UnsafeShutdowns = *meta.SMART.UnsafeShutdowns
}
}
return storagehealth.AssessSample(sample)
}
func physicalDiskStatus(model, health string, assessment storagehealth.Assessment) ResourceStatus {
switch assessment.Level {
case storagehealth.RiskCritical, storagehealth.RiskWarning:
return StatusWarning
}
switch strings.ToUpper(strings.TrimSpace(health)) {
case "PASSED", "OK":
return StatusOnline
case "FAILED":
if storagehealth.HasKnownFirmwareBug(model) {
return StatusUnknown
}
return StatusOffline
default:
return StatusUnknown
}
}
// PhysicalDiskStatus applies the canonical shared physical-disk status policy
// for providers that already calculated a disk-health assessment.
func PhysicalDiskStatus(model, health string, assessment storagehealth.Assessment) ResourceStatus {
return physicalDiskStatus(model, health, assessment)
}