From cd44aab61f0b59302708cfb519fb3b5fb395f0da Mon Sep 17 00:00:00 2001 From: rare-magma Date: Wed, 15 Jun 2022 23:01:53 +0200 Subject: [PATCH] handle smart errors, use ParseAsTemperature() --- devices/temp_nix.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/devices/temp_nix.go b/devices/temp_nix.go index dcb8ed4..e6d3f57 100644 --- a/devices/temp_nix.go +++ b/devices/temp_nix.go @@ -48,18 +48,23 @@ func getTemps(temps map[string]int) map[string]error { switch sm := dev.(type) { case *smart.SataDevice: - data, _ := sm.ReadSMARTData() + data, err := sm.ReadSMARTData() if err != nil { - log.Print("error getting smart data") + log.Print("error getting smart data for " + disk.Name + "_" + disk.Model) return nil } if attr, ok := data.Attrs[194]; ok { - temps[disk.Name+"_"+disk.Model] = int(attr.Value) + val, _, _, _, err := attr.ParseAsTemperature() + if err != nil { + log.Print("error parsing temperature smart data for " + disk.Name + "_" + disk.Model) + return nil + } + temps[disk.Name+"_"+disk.Model] = int(val) } case *smart.NVMeDevice: - data, _ := sm.ReadSMART() + data, err := sm.ReadSMART() if err != nil { - log.Print("error getting smart data") + log.Print("error getting smart data for " + disk.Name + "_" + disk.Model) return nil } temps[disk.Name+"_"+disk.Model] = int(data.Temperature)