@cryptotaxi247 / netdata-1 / commits / f1b3d6aff

fix(go.d/nvme): add missing "/dev/" prefix to device path for v2.11 (#19577)

Ilya Mashchenko committed Feb 5, 2025 at 11:51 UTC f1b3d6affd585e22a4508f3422b2a263fffa10a8
2 files changed +11 -2
src/go/plugin/go.d/collector/nvme/collector_test.go
+5 -1
@@ -10,6 +10,7 @@ import (
10 "errors"
11 "fmt"
12 "os"
13 + "strings"
14 "testing"
15
16 "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
@@ -515,10 +516,13 @@ func (m *mockNVMeCLIExec) list() (*nvmeDeviceList, error) {
516 return &v, nil
517 }
518
518 -func (m *mockNVMeCLIExec) smartLog(_ string) (*nvmeDeviceSmartLog, error) {
519 +func (m *mockNVMeCLIExec) smartLog(device string) (*nvmeDeviceSmartLog, error) {
520 if m.errOnSmartLog {
521 return nil, errors.New("mock.smartLog() error")
522 }
523 + if !strings.HasPrefix(device, "/dev/") {
524 + return nil, errors.New("mock.smartLog() expects device path /dev/")
525 + }
526
527 var v nvmeDeviceSmartLog
528 if err := json.Unmarshal(m.dataSmartLog, &v); err != nil {
src/go/plugin/go.d/collector/nvme/exec.go
+6 -1
@@ -10,6 +10,7 @@ import (
10 "encoding/json"
11 "os/exec"
12 "strconv"
13 + "strings"
14 "time"
15 )
16
@@ -58,13 +59,17 @@ func (n *nvmeDeviceList) UnmarshalJSON(b []byte) error {
59 for _, subsystem := range device.Subsystems {
60 for _, controller := range subsystem.Controllers {
61 for _, namespace := range controller.Namespaces {
62 + devPath := namespace.NameSpace
63 + if !strings.HasPrefix(devPath, "/dev/") {
64 + devPath = "/dev/" + devPath
65 + }
66 n.Devices = append(n.Devices, struct {
67 DevicePath string `json:"DevicePath"`
68 Firmware string `json:"Firmware"`
69 ModelNumber string `json:"ModelNumber"`
70 SerialNumber string `json:"SerialNumber"`
71 }{
67 - DevicePath: namespace.NameSpace,
72 + DevicePath: devPath,
73 Firmware: controller.Firmware,
74 ModelNumber: controller.ModelNumber,
75 SerialNumber: controller.SerialNumber,