| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package storcli |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "os" |
| 8 | "path/filepath" |
| 9 | "runtime" |
| 10 | |
| 11 | "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/ndexec" |
| 12 | ) |
| 13 | |
| 14 | func (c *Collector) initStorCliExec() (storCli, error) { |
| 15 | if runtime.GOOS == "windows" { |
| 16 | return c.initDirectStorCliExec() |
| 17 | } |
| 18 | return c.initNdsudoStorCliExec() |
| 19 | } |
| 20 | |
| 21 | func (c *Collector) initNdsudoStorCliExec() (storCli, error) { |
| 22 | storExec := newNdsudoStorCliExec(c.Timeout.Duration(), c.Logger) |
| 23 | return storExec, nil |
| 24 | } |
| 25 | |
| 26 | func (c *Collector) initDirectStorCliExec() (storCli, error) { |
| 27 | path, err := ndexec.FindBinary( |
| 28 | []string{"storcli", "storcli64", "StorCLI", "StorCLI64"}, |
| 29 | []string{ |
| 30 | filepath.Join(os.Getenv("ProgramFiles"), "Broadcom", "StorCLI", "storcli64.exe"), |
| 31 | filepath.Join(os.Getenv("ProgramFiles"), "LSI", "StorCLI", "storcli64.exe"), |
| 32 | filepath.Join(os.Getenv("ProgramFiles(x86)"), "StorCLI", "storcli64.exe"), |
| 33 | }, |
| 34 | ) |
| 35 | if err != nil { |
| 36 | return nil, fmt.Errorf("storcli: %w", err) |
| 37 | } |
| 38 | |
| 39 | c.Debugf("found storcli at: %s", path) |
| 40 | |
| 41 | return newDirectStorCliExec(path, c.Timeout.Duration(), c.Logger), nil |
| 42 | } |