From 550cd59093edb89a8f40dc04f2258d2c179f33e4 Mon Sep 17 00:00:00 2001 From: Aram Akhavan Date: Sat, 14 Oct 2023 21:39:12 -0700 Subject: [PATCH] Fix parsing of attribute 188 on seagate drives --- .../pkg/thresholds/ata_attribute_metadata.go | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/webapp/backend/pkg/thresholds/ata_attribute_metadata.go b/webapp/backend/pkg/thresholds/ata_attribute_metadata.go index 11eb5a6a..423d72a0 100644 --- a/webapp/backend/pkg/thresholds/ata_attribute_metadata.go +++ b/webapp/backend/pkg/thresholds/ata_attribute_metadata.go @@ -1,5 +1,10 @@ package thresholds +import ( + "strconv" + "strings" +) + const AtaSmartAttributeDisplayTypeRaw = "raw" const AtaSmartAttributeDisplayTypeNormalized = "normalized" const AtaSmartAttributeDisplayTypeTransformed = "transformed" @@ -662,13 +667,33 @@ var AtaMetadata = map[int]AtaAttributeMetadata{ 188: { ID: 188, DisplayName: "Command Timeout", - DisplayType: AtaSmartAttributeDisplayTypeRaw, + DisplayType: AtaSmartAttributeDisplayTypeTransformed, Ideal: ObservedThresholdIdealLow, Critical: true, Description: "The count of aborted operations due to HDD timeout. Normally this attribute value should be equal to zero.", + Transform: func(normValue int64, rawValue int64, rawString string) int64 { + // Parse Seagate command timeout values if the string contains 3 pieces + // and each piece is less than or equal to the next (as a sanity check) + // See https://github.com/AnalogJ/scrutiny/issues/522 + pieces := strings.Split(rawString, " ") + if len(pieces) == 3 { + int_pieces := make([]int, len(pieces)) + var err error + for i, s := range pieces { + int_pieces[i], err = strconv.Atoi(s) + if err != nil { + return rawValue + } + } + if int_pieces[2] >= int_pieces[1] && int_pieces[1] >= int_pieces[0] { + return int64(int_pieces[2]) + } + } + return rawValue + }, ObservedThresholds: []ObservedThreshold{ { - Low: 0, + Low: 0, // This is set arbitrarily to avoid notifications caused by low // historical numbers of command timeouts (e.g. caused by a bad cable) High: 100,