| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package portcheck |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "net" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | type dialTCPFunc func(network, address string, timeout time.Duration) (net.Conn, error) |
| 12 | |
| 13 | func (c *Collector) validateConfig() error { |
| 14 | if c.Host == "" { |
| 15 | return errors.New("missing required parameter: 'host' must be specified") |
| 16 | } |
| 17 | if len(c.Ports) == 0 && len(c.UDPPorts) == 0 { |
| 18 | return errors.New("missing required parameters: at least one of 'ports' (TCP) or 'udp_ports' (UDP) must be specified") |
| 19 | } |
| 20 | return nil |
| 21 | } |
| 22 | |
| 23 | func (c *Collector) initPorts() (tcpPorts []*tcpPort, udpPorts []*udpPort) { |
| 24 | for _, p := range c.Ports { |
| 25 | tcpPorts = append(tcpPorts, &tcpPort{number: p}) |
| 26 | } |
| 27 | for _, p := range c.UDPPorts { |
| 28 | udpPorts = append(udpPorts, &udpPort{number: p}) |
| 29 | } |
| 30 | |
| 31 | return tcpPorts, udpPorts |
| 32 | } |