master
go 61 lines 1.53 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package storcli
4
5 import (
6 "time"
7
8 "github.com/netdata/netdata/go/plugins/logger"
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/ndexec"
10 )
11
12 type storCli interface {
13 controllersInfo() ([]byte, error)
14 drivesInfo() ([]byte, error)
15 }
16
17 // ndsudoStorCliExec executes storcli via ndsudo (Linux/BSD)
18 type ndsudoStorCliExec struct {
19 *logger.Logger
20
21 timeout time.Duration
22 }
23
24 func newNdsudoStorCliExec(timeout time.Duration, log *logger.Logger) *ndsudoStorCliExec {
25 return &ndsudoStorCliExec{
26 Logger: log,
27 timeout: timeout,
28 }
29 }
30
31 func (e *ndsudoStorCliExec) controllersInfo() ([]byte, error) {
32 return ndexec.RunNDSudo(e.Logger, e.timeout, "storcli-controllers-info")
33 }
34
35 func (e *ndsudoStorCliExec) drivesInfo() ([]byte, error) {
36 return ndexec.RunNDSudo(e.Logger, e.timeout, "storcli-drives-info")
37 }
38
39 // directStorCliExec executes storcli directly (Windows)
40 type directStorCliExec struct {
41 *logger.Logger
42
43 storcliPath string
44 timeout time.Duration
45 }
46
47 func newDirectStorCliExec(storcliPath string, timeout time.Duration, log *logger.Logger) *directStorCliExec {
48 return &directStorCliExec{
49 Logger: log,
50 storcliPath: storcliPath,
51 timeout: timeout,
52 }
53 }
54
55 func (e *directStorCliExec) controllersInfo() ([]byte, error) {
56 return ndexec.RunDirect(e.Logger, e.timeout, e.storcliPath, "/cALL", "show", "all", "J", "nolog")
57 }
58
59 func (e *directStorCliExec) drivesInfo() ([]byte, error) {
60 return ndexec.RunDirect(e.Logger, e.timeout, e.storcliPath, "/cALL/eALL/sALL", "show", "all", "J", "nolog")
61 }