diff options
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/portcheck/init.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/portcheck/init.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/portcheck/init.go b/src/go/collectors/go.d.plugin/modules/portcheck/init.go new file mode 100644 index 000000000..29c0e43a0 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/portcheck/init.go @@ -0,0 +1,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 +} |