refactor: dedupe status-severity ranking and small webui helpers

statusSeverity was byte-for-byte duplicated in collector/contract.go and
app/sat_overlay.go (same switch, same comment). Export it as
collector.StatusSeverity and drop the app-package copy.

page_topo.go inlined the same GPU/NIC/RAID class switch as its own
pcieDeviceKind function in one spot — call the function instead.

page_validate.go had its own copy of pages.go's firstNonEmpty (all call
sites already pre-trim their inputs via validateTrimPtr, so the extra
TrimSpace was redundant) — drop the duplicate.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-08-18 14:44:52 +03:00
co-authored by Claude Sonnet 5
parent e3697c0a11
commit 134bed3eae
4 changed files with 14 additions and 46 deletions
+4 -19
View File
@@ -237,7 +237,7 @@ func parseStorageSATStatus(summary satSummary) map[string]satStatusResult {
}
}
current := result[devName]
if !current.ok || statusSeverity(stepStatus) > statusSeverity(current.status) {
if !current.ok || collector.StatusSeverity(stepStatus) > collector.StatusSeverity(current.status) {
result[devName] = satStatusResult{status: stepStatus, description: desc, ok: true}
}
}
@@ -279,7 +279,7 @@ func mergeComponentStatus(component *schema.HardwareComponentStatus, changedAt,
return
}
current := strings.TrimSpace(ptrString(component.Status))
if current == "" || current == "Unknown" || statusSeverity(satStatus) > statusSeverity(current) {
if current == "" || current == "Unknown" || collector.StatusSeverity(satStatus) > collector.StatusSeverity(current) {
component.Status = appStringPtr(satStatus)
if strings.TrimSpace(description) != "" {
component.ErrorDescription = appStringPtr(description)
@@ -300,8 +300,8 @@ func mergeComponentStatusPreferDetail(component *schema.HardwareComponentStatus,
return
}
current := strings.TrimSpace(ptrString(component.Status))
newSeverity := statusSeverity(satStatus)
currentSeverity := statusSeverity(current)
newSeverity := collector.StatusSeverity(satStatus)
currentSeverity := collector.StatusSeverity(current)
if current == "" || current == "Unknown" || newSeverity > currentSeverity {
mergeComponentStatus(component, changedAt, satStatus, description)
return
@@ -320,21 +320,6 @@ func mergeComponentStatusPreferDetail(component *schema.HardwareComponentStatus,
}
}
func statusSeverity(status string) int {
switch strings.TrimSpace(status) {
case "Critical":
return 3
case "Warning":
return 2
case "OK":
return 1
case "Unknown":
return 1 // same as OK — does not override OK from another source
default:
return 0
}
}
func matchesGPUVendor(dev schema.HardwarePCIeDevice, vendor string) bool {
if dev.DeviceClass == nil {
return false