Lightweight server monitoring with historical data, docker stats, and alerts.
fix(agent): widen NVMe unsafe_shutdowns to uint (#2583)
Bharat Kaurav383e9c707249
diff --git a/agent/smart.go b/agent/smart.goindex 4dc1497f4..0834d19e4 100644--- a/agent/smart.go+++ b/agent/smart.go@@ -1138,6 +1138,7 @@ func (sm *SmartManager) parseSmartForNvme(output []byte, deviceType string) (boodata := &smart.SmartInfoForNvme{}if err := json.Unmarshal(output, &data); err != nil {+ slog.Debug("failed to parse NVMe smartctl output", "err", err)return false, 0}diff --git a/agent/smart_test.go b/agent/smart_test.goindex 61860a725..f403abb7f 100644--- a/agent/smart_test.go+++ b/agent/smart_test.go@@ -7,6 +7,7 @@ import ("fmt""os""path/filepath"+ "regexp""strings""testing"@@ -292,6 +293,29 @@ func TestParseSmartForNvme(t *testing.T) {}}+func TestParseSmartForNvmeLargeUnsafeShutdowns(t *testing.T) {+ fixturePath := filepath.Join("test-data", "smart", "nvme0.json")+ data, err := os.ReadFile(fixturePath)+ require.NoError(t, err)++ // Some drives report counts that overflow uint16, which previously made the+ // whole record fail to unmarshal and get discarded.+ re := regexp.MustCompile(`"unsafe_shutdowns":\s*\d+`)+ require.True(t, re.Match(data), "fixture should contain unsafe_shutdowns")+ data = re.ReplaceAll(data, []byte(`"unsafe_shutdowns": 159754`))++ sm := &SmartManager{+ SmartDataMap: make(map[string]*smart.SmartData),+ }++ hasData, _ := sm.parseSmartForNvme(data, "")+ require.True(t, hasData)++ deviceData, ok := sm.SmartDataMap["2024031600129"]+ require.True(t, ok, "expected smart data entry for serial 2024031600129")+ assertAttrValue(t, deviceData.Attributes, "UnsafeShutdowns", 159754)+}+func TestHasDataForDevice(t *testing.T) {sm := &SmartManager{SmartDataMap: map[string]*smart.SmartData{diff --git a/internal/entities/smart/smart.go b/internal/entities/smart/smart.goindex 694522e59..55aee622f 100644--- a/internal/entities/smart/smart.go+++ b/internal/entities/smart/smart.go@@ -477,7 +477,7 @@ type NVMeSmartHealthInformationLog struct {ControllerBusyTime uint `json:"controller_busy_time"`PowerCycles uint `json:"power_cycles"`PowerOnHours uint32 `json:"power_on_hours"`- UnsafeShutdowns uint16 `json:"unsafe_shutdowns"`+ UnsafeShutdowns uint `json:"unsafe_shutdowns"`MediaErrors uint `json:"media_errors"`NumErrLogEntries uint `json:"num_err_log_entries"`WarningTempTime uint `json:"warning_temp_time"`