diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/go/collectors/go.d.plugin/modules/portcheck/init.go | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-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..0d1649690 --- /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) { + var 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 +} |