master
go 61 lines 1.49 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package megacli
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 megaCli interface {
13 physDrivesInfo() ([]byte, error)
14 bbuInfo() ([]byte, error)
15 }
16
17 // ndsudoMegaCliExec executes megacli via ndsudo (Linux/BSD)
18 type ndsudoMegaCliExec struct {
19 *logger.Logger
20
21 timeout time.Duration
22 }
23
24 func newNdsudoMegaCliExec(timeout time.Duration, log *logger.Logger) *ndsudoMegaCliExec {
25 return &ndsudoMegaCliExec{
26 Logger: log,
27 timeout: timeout,
28 }
29 }
30
31 func (e *ndsudoMegaCliExec) physDrivesInfo() ([]byte, error) {
32 return ndexec.RunNDSudo(e.Logger, e.timeout, "megacli-disk-info")
33 }
34
35 func (e *ndsudoMegaCliExec) bbuInfo() ([]byte, error) {
36 return ndexec.RunNDSudo(e.Logger, e.timeout, "megacli-battery-info")
37 }
38
39 // directMegaCliExec executes megacli directly (Windows)
40 type directMegaCliExec struct {
41 *logger.Logger
42
43 megacliPath string
44 timeout time.Duration
45 }
46
47 func newDirectMegaCliExec(megacliPath string, timeout time.Duration, log *logger.Logger) *directMegaCliExec {
48 return &directMegaCliExec{
49 Logger: log,
50 megacliPath: megacliPath,
51 timeout: timeout,
52 }
53 }
54
55 func (e *directMegaCliExec) physDrivesInfo() ([]byte, error) {
56 return ndexec.RunDirect(e.Logger, e.timeout, e.megacliPath, "-LDPDInfo", "-aAll", "-NoLog")
57 }
58
59 func (e *directMegaCliExec) bbuInfo() ([]byte, error) {
60 return ndexec.RunDirect(e.Logger, e.timeout, e.megacliPath, "-AdpBbuCmd", "-aAll", "-NoLog")
61 }