improved aligned printing

This commit is contained in:
lukas-heiligenbrunner 2022-05-05 12:41:16 +02:00
parent bd5d4414bd
commit a2284e54a8

View File

@ -75,6 +75,10 @@ func getTemp(diskpath string) (uint32, uint32, uint32) {
return uint32(max), uint32(min), uint32(currtemp) return uint32(max), uint32(min), uint32(currtemp)
} }
func printAligned(paramname string, valuestr string) {
fmt.Printf("%-24v%s\n", paramname+":", valuestr)
}
func checkSmartAttributes(diskpath string, isSeagate bool, isHdd bool) { func checkSmartAttributes(diskpath string, isSeagate bool, isHdd bool) {
rawattr := getSmartValues(diskpath) rawattr := getSmartValues(diskpath)
@ -85,17 +89,17 @@ func checkSmartAttributes(diskpath string, isSeagate bool, isHdd bool) {
// error count| operation count // error count| operation count
rrerrrate = rrerrrate >> 32 rrerrrate = rrerrrate >> 32
} }
fmt.Println("Raw_Read_Error_Rate: " + evalStrZero(rrerrrate)) printAligned("Raw_Read_Error_Rate", evalStrZero(rrerrrate))
fmt.Println("Reallocated_Sector_Ct: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reallocated_Sector_Ct"))) printAligned("Reallocated_Sector_Ct", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reallocated_Sector_Ct")))
// todo further investigate if this smart attributes can occur within hdds/ssds // todo further investigate if this smart attributes can occur within hdds/ssds
// https://www.backblaze.com/blog/what-smart-stats-indicate-hard-drive-failures/ // https://www.backblaze.com/blog/what-smart-stats-indicate-hard-drive-failures/
fmt.Println("Reported_Uncorrect: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reported_Uncorrect"))) printAligned("Reported_Uncorrect", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reported_Uncorrect")))
fmt.Println("Command_Timeout: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Command_Timeout"))) printAligned("Command_Timeout", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Command_Timeout")))
fmt.Println("Current_Pending_Sector: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Current_Pending_Sector"))) printAligned("Current_Pending_Sector", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Current_Pending_Sector")))
fmt.Println("Offline_Uncorrectable: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Offline_Uncorrectable"))) printAligned("Offline_Uncorrectable", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Offline_Uncorrectable")))
// there are some additinoal hdd smart values // there are some additinoal hdd only smart values
if isHdd { if isHdd {
rrerrrate = getItemValue(rawattr.AtaSmartAttr.Table, "Seek_Error_Rate") rrerrrate = getItemValue(rawattr.AtaSmartAttr.Table, "Seek_Error_Rate")
if isSeagate { if isSeagate {
@ -103,9 +107,11 @@ func checkSmartAttributes(diskpath string, isSeagate bool, isHdd bool) {
// error count| operation count // error count| operation count
rrerrrate = rrerrrate >> 32 rrerrrate = rrerrrate >> 32
} }
fmt.Println("Seek_Error_Rate:\t" + evalStrZero(rrerrrate)) printAligned("Seek_Error_Rate", evalStrZero(rrerrrate))
fmt.Println("Spin_Retry_Count:\t" + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Spin_Retry_Count"))) printAligned("Spin_Retry_Count", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Spin_Retry_Count")))
fmt.Println("Spin_Up_Time:\t\t" + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Spin_Up_Time"))) printAligned("Spin_Up_Time", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Spin_Up_Time")))
} else {
// todo ssd only parameters
} }
} }
@ -113,9 +119,9 @@ func evalStrZero(nr int64) string {
if nr < 0 { if nr < 0 {
return "N/A" return "N/A"
} else if nr == 0 { } else if nr == 0 {
return "\tPASS" return "PASS"
} else { } else {
return fmt.Sprintf("\tFAIL :: raw value=%d", nr) return fmt.Sprintf("FAIL :: raw value=%d", nr)
} }
} }