summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/modules/sensors/exec.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 08:15:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 08:15:20 +0000
commit87d772a7d708fec12f48cd8adc0dedff6e1025da (patch)
tree1fee344c64cc3f43074a01981e21126c8482a522 /src/go/plugin/go.d/modules/sensors/exec.go
parentAdding upstream version 1.46.3. (diff)
downloadnetdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.tar.xz
netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.zip
Adding upstream version 1.47.0.upstream/1.47.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/plugin/go.d/modules/sensors/exec.go')
-rw-r--r--src/go/plugin/go.d/modules/sensors/exec.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/go/plugin/go.d/modules/sensors/exec.go b/src/go/plugin/go.d/modules/sensors/exec.go
new file mode 100644
index 000000000..c386ddd7d
--- /dev/null
+++ b/src/go/plugin/go.d/modules/sensors/exec.go
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package sensors
+
+import (
+ "context"
+ "fmt"
+ "os/exec"
+ "time"
+
+ "github.com/netdata/netdata/go/plugins/logger"
+)
+
+func newSensorsCliExec(binPath string, timeout time.Duration) *sensorsCliExec {
+ return &sensorsCliExec{
+ binPath: binPath,
+ timeout: timeout,
+ }
+}
+
+type sensorsCliExec struct {
+ *logger.Logger
+
+ binPath string
+ timeout time.Duration
+}
+
+func (e *sensorsCliExec) sensorsInfo() ([]byte, error) {
+ ctx, cancel := context.WithTimeout(context.Background(), e.timeout)
+ defer cancel()
+
+ cmd := exec.CommandContext(ctx, e.binPath, "-A", "-u")
+ 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
+}