| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package postfix |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "os" |
| 8 | "os/exec" |
| 9 | "strings" |
| 10 | |
| 11 | "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/pathvalidate" |
| 12 | ) |
| 13 | |
| 14 | func (c *Collector) validateConfig() error { |
| 15 | if c.BinaryPath == "" { |
| 16 | return errors.New("no postqueue binary path specified") |
| 17 | } |
| 18 | return nil |
| 19 | } |
| 20 | |
| 21 | func (c *Collector) initPostqueueExec() (postqueueBinary, error) { |
| 22 | binPath := c.BinaryPath |
| 23 | |
| 24 | if !strings.HasPrefix(binPath, "/") { |
| 25 | path, err := exec.LookPath(binPath) |
| 26 | if err != nil { |
| 27 | return nil, err |
| 28 | } |
| 29 | binPath = path |
| 30 | } |
| 31 | |
| 32 | if _, err := os.Stat(binPath); err != nil { |
| 33 | return nil, err |
| 34 | } |
| 35 | |
| 36 | validatedPath, err := pathvalidate.ValidateBinaryPath(binPath) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | |
| 41 | pq := newPostqueueExec(validatedPath, c.Timeout.Duration()) |
| 42 | pq.Logger = c.Logger |
| 43 | |
| 44 | return pq, nil |
| 45 | } |