summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/zfspool/init.go
blob: d4debe3fa019df4ed1249e59d3d8063109dabfce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: GPL-3.0-or-later

package zfspool

import (
	"errors"
	"os"
	"os/exec"
	"strings"
)

func (z *ZFSPool) validateConfig() error {
	if z.BinaryPath == "" {
		return errors.New("no zpool binary path specified")
	}
	return nil
}

func (z *ZFSPool) initZPoolCLIExec() (zpoolCLI, error) {
	binPath := z.BinaryPath

	if !strings.HasPrefix(binPath, "/") {
		path, err := exec.LookPath(binPath)
		if err != nil {
			return nil, err
		}
		binPath = path
	}

	if _, err := os.Stat(binPath); err != nil {
		return nil, err
	}

	zpoolExec := newZpoolCLIExec(binPath, z.Timeout.Duration())

	return zpoolExec, nil
}