master
go 36 lines 683 Bytes
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package chrony
4
5 import (
6 "errors"
7 "net"
8 )
9
10 func (c *Collector) validateConfig() error {
11 if c.Address == "" {
12 return errors.New("empty 'address'")
13 }
14 return nil
15 }
16
17 func (c *Collector) initChronycBinary() (chronyBinary, error) {
18 host, _, err := net.SplitHostPort(c.Address)
19 if err != nil {
20 return nil, err
21 }
22
23 // 'serverstats' allowed only through the Unix domain socket
24 if !isLocalhost(host) {
25 return nil, nil
26 }
27
28 chronyc := newChronycExec(c.Timeout.Duration(), c.Logger)
29
30 return chronyc, nil
31 }
32
33 func isLocalhost(host string) bool {
34 ip := net.ParseIP(host)
35 return host == "localhost" || (ip != nil && ip.IsLoopback())
36 }