diff --git a/smartdiskinfo.go b/smartdiskinfo.go index b3c2e2c..9694ed2 100644 --- a/smartdiskinfo.go +++ b/smartdiskinfo.go @@ -75,6 +75,10 @@ func getTemp(diskpath string) (uint32, uint32, uint32) { 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) { rawattr := getSmartValues(diskpath) @@ -85,17 +89,17 @@ func checkSmartAttributes(diskpath string, isSeagate bool, isHdd bool) { // error count| operation count rrerrrate = rrerrrate >> 32 } - fmt.Println("Raw_Read_Error_Rate: " + evalStrZero(rrerrrate)) - fmt.Println("Reallocated_Sector_Ct: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reallocated_Sector_Ct"))) + printAligned("Raw_Read_Error_Rate", evalStrZero(rrerrrate)) + printAligned("Reallocated_Sector_Ct", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reallocated_Sector_Ct"))) // todo further investigate if this smart attributes can occur within hdds/ssds // https://www.backblaze.com/blog/what-smart-stats-indicate-hard-drive-failures/ - fmt.Println("Reported_Uncorrect: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reported_Uncorrect"))) - fmt.Println("Command_Timeout: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Command_Timeout"))) - fmt.Println("Current_Pending_Sector: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Current_Pending_Sector"))) - fmt.Println("Offline_Uncorrectable: " + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Offline_Uncorrectable"))) + printAligned("Reported_Uncorrect", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Reported_Uncorrect"))) + printAligned("Command_Timeout", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Command_Timeout"))) + printAligned("Current_Pending_Sector", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Current_Pending_Sector"))) + 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 { rrerrrate = getItemValue(rawattr.AtaSmartAttr.Table, "Seek_Error_Rate") if isSeagate { @@ -103,9 +107,11 @@ func checkSmartAttributes(diskpath string, isSeagate bool, isHdd bool) { // error count| operation count rrerrrate = rrerrrate >> 32 } - fmt.Println("Seek_Error_Rate:\t" + evalStrZero(rrerrrate)) - fmt.Println("Spin_Retry_Count:\t" + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Spin_Retry_Count"))) - fmt.Println("Spin_Up_Time:\t\t" + evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Spin_Up_Time"))) + printAligned("Seek_Error_Rate", evalStrZero(rrerrrate)) + printAligned("Spin_Retry_Count", evalStrZero(getItemValue(rawattr.AtaSmartAttr.Table, "Spin_Retry_Count"))) + 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 { return "N/A" } else if nr == 0 { - return "\tPASS" + return "PASS" } else { - return fmt.Sprintf("\tFAIL :: raw value=%d", nr) + return fmt.Sprintf("FAIL :: raw value=%d", nr) } }