summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/storcli/exec.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/storcli/exec.go')
-rw-r--r--src/go/collectors/go.d.plugin/modules/storcli/exec.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/storcli/exec.go b/src/go/collectors/go.d.plugin/modules/storcli/exec.go
new file mode 100644
index 0000000000..3375ddbe4f
--- /dev/null
+++ b/src/go/collectors/go.d.plugin/modules/storcli/exec.go
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package storcli
+
+import (
+ "context"
+ "fmt"
+ "os/exec"
+ "time"
+
+ "github.com/netdata/netdata/go/go.d.plugin/logger"
+)
+
+func newStorCliExec(ndsudoPath string, timeout time.Duration, log *logger.Logger) *storCliExec {
+ return &storCliExec{
+ Logger: log,
+ ndsudoPath: ndsudoPath,
+ timeout: timeout,
+ }
+}
+
+type storCliExec struct {
+ *logger.Logger
+
+ ndsudoPath string
+ timeout time.Duration
+}
+
+func (e *storCliExec) controllersInfo() ([]byte, error) {
+ return e.execute("storcli-controllers-info")
+}
+
+func (e *storCliExec) drivesInfo() ([]byte, error) {
+ return e.execute("storcli-drives-info")
+}
+
+func (e *storCliExec) execute(args ...string) ([]byte, error) {
+ ctx, cancel := context.WithTimeout(context.Background(), e.timeout)
+ defer cancel()
+
+ cmd := exec.CommandContext(ctx, e.ndsudoPath, args...)
+ e.Debugf("executing '%s'", cmd)
+
+ bs, err := cmd.Output()
+ if err != nil {
+ return nil, fmt.Errorf("error on '%s': %v", cmd, err)
+ }
+
+ return bs, nil
+}