| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package megacli |
| 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) initMegaCliExec() (megaCli, error) { |
| 15 | if runtime.GOOS == "windows" { |
| 16 | return c.initDirectMegaCliExec() |
| 17 | } |
| 18 | return c.initNdsudoMegaCliExec() |
| 19 | } |
| 20 | |
| 21 | func (c *Collector) initNdsudoMegaCliExec() (megaCli, error) { |
| 22 | megaExec := newNdsudoMegaCliExec(c.Timeout.Duration(), c.Logger) |
| 23 | return megaExec, nil |
| 24 | } |
| 25 | |
| 26 | func (c *Collector) initDirectMegaCliExec() (megaCli, error) { |
| 27 | path, err := ndexec.FindBinary( |
| 28 | []string{"megacli", "MegaCli", "MegaCli64", "megacli64"}, |
| 29 | []string{ |
| 30 | filepath.Join(os.Getenv("ProgramFiles"), "LSI", "MegaCLI", "MegaCli64.exe"), |
| 31 | filepath.Join(os.Getenv("ProgramFiles"), "Broadcom", "MegaCLI", "MegaCli64.exe"), |
| 32 | filepath.Join(os.Getenv("ProgramFiles(x86)"), "MegaCLI", "MegaCli64.exe"), |
| 33 | }, |
| 34 | ) |
| 35 | if err != nil { |
| 36 | return nil, fmt.Errorf("megacli: %w", err) |
| 37 | } |
| 38 | |
| 39 | c.Debugf("found megacli at: %s", path) |
| 40 | |
| 41 | return newDirectMegaCliExec(path, c.Timeout.Duration(), c.Logger), nil |
| 42 | } |