@cryptotaxi247 / netdata / commits / c110045f2

improve(go.d/smartctl): add Win default path for smartctl executable (#20574)

Ilya Mashchenko committed Jun 25, 2025 at 10:17 UTC c110045f2c1efc4610e3fc8c5f4273cd8b40d3e0
2 files changed +16 -9
src/go/plugin/go.d/collector/smartctl/exec.go
+7 -5
@@ -74,13 +74,15 @@ func (e *ndsudoSmartctlCli) execute(args ...string) (*gjson.Result, error) {
74 type directSmartctlCli struct {
75 *logger.Logger
76
77 - timeout time.Duration
77 + smartctlPath string
78 + timeout time.Duration
79 }
80
80 -func newDirectSmartctlCli(timeout time.Duration, log *logger.Logger) *directSmartctlCli {
81 +func newDirectSmartctlCli(smartctlPath string, timeout time.Duration, log *logger.Logger) *directSmartctlCli {
82 return &directSmartctlCli{
82 - Logger: log,
83 - timeout: timeout,
83 + Logger: log,
84 + smartctlPath: smartctlPath,
85 + timeout: timeout,
86 }
87 }
88
@@ -107,7 +109,7 @@ func (e *directSmartctlCli) execute(args ...string) (*gjson.Result, error) {
109 ctx, cancel := context.WithTimeout(context.Background(), e.timeout)
110 defer cancel()
111
110 - cmd := exec.CommandContext(ctx, "smartctl", args...)
112 + cmd := exec.CommandContext(ctx, e.smartctlPath, args...)
113 e.Debugf("executing '%s'", cmd)
114
115 bs, err := cmd.Output()
src/go/plugin/go.d/collector/smartctl/init.go
+9 -4
@@ -60,14 +60,19 @@ func (c *Collector) initNdsudoSmartctlCli() (smartctlCli, error) {
60 }
61
62 func (c *Collector) initDirectSmartctlCli() (smartctlCli, error) {
63 - // Check if smartctl is available in PATH
63 smartctlPath, err := exec.LookPath("smartctl")
64 if err != nil {
66 - return nil, fmt.Errorf("smartctl executable not found in PATH: %v", err)
65 + if runtime.GOOS != "windows" {
66 + return nil, fmt.Errorf("smartctl executable not found in PATH: %v", err)
67 + }
68 + defaultWinPath := filepath.Join("C:\\Program Files\\smartmontools\\bin", "smartctl.exe")
69 + if _, err := os.Stat(defaultWinPath); err != nil {
70 + return nil, fmt.Errorf("smartctl executable not found in PATH or default location: %v", err)
71 + }
72 + smartctlPath = defaultWinPath
73 }
74
75 c.Debugf("found smartctl at: %s", smartctlPath)
70 -
71 - smartctlExec := newDirectSmartctlCli(c.Timeout.Duration(), c.Logger)
76 + smartctlExec := newDirectSmartctlCli(smartctlPath, c.Timeout.Duration(), c.Logger)
77 return smartctlExec, nil
78 }