| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | //go:build linux || freebsd || openbsd || netbsd || dragonfly |
| 4 | |
| 5 | package zfspool |
| 6 | |
| 7 | import ( |
| 8 | "time" |
| 9 | |
| 10 | "github.com/netdata/netdata/go/plugins/logger" |
| 11 | "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/ndexec" |
| 12 | ) |
| 13 | |
| 14 | type zpoolCli interface { |
| 15 | list() ([]byte, error) |
| 16 | listWithVdev(pool string) ([]byte, error) |
| 17 | } |
| 18 | |
| 19 | func newZpoolCLIExec(binPath string, timeout time.Duration) *zpoolCLIExec { |
| 20 | return &zpoolCLIExec{ |
| 21 | binPath: binPath, |
| 22 | timeout: timeout, |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | type zpoolCLIExec struct { |
| 27 | *logger.Logger |
| 28 | |
| 29 | binPath string |
| 30 | timeout time.Duration |
| 31 | } |
| 32 | |
| 33 | func (e *zpoolCLIExec) list() ([]byte, error) { |
| 34 | return ndexec.RunUnprivileged(e.Logger, e.timeout, e.binPath, "list", "-p") |
| 35 | } |
| 36 | |
| 37 | func (e *zpoolCLIExec) listWithVdev(pool string) ([]byte, error) { |
| 38 | return ndexec.RunUnprivileged(e.Logger, e.timeout, e.binPath, "list", "-p", "-v", "-L", pool) |
| 39 | } |