blob: 29c0e43a03af952a1e96518a3e53689c09eb4fd4 (
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
38
39
40
41
42
43
44
45
46
47
48
49
|
// SPDX-License-Identifier: GPL-3.0-or-later
package portcheck
import (
"errors"
"net"
"time"
"github.com/netdata/netdata/go/go.d.plugin/agent/module"
)
type dialFunc func(network, address string, timeout time.Duration) (net.Conn, error)
type port struct {
number int
state checkState
inState int
latency int
}
func (pc *PortCheck) validateConfig() error {
if pc.Host == "" {
return errors.New("'host' parameter not set")
}
if len(pc.Ports) == 0 {
return errors.New("'ports' parameter not set")
}
return nil
}
func (pc *PortCheck) initCharts() (*module.Charts, error) {
charts := module.Charts{}
for _, port := range pc.Ports {
if err := charts.Add(*newPortCharts(pc.Host, port)...); err != nil {
return nil, err
}
}
return &charts, nil
}
func (pc *PortCheck) initPorts() (ports []*port) {
for _, p := range pc.Ports {
ports = append(ports, &port{number: p})
}
return ports
}
|