Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
ping: add "network" config option (#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Sep 27, 2023
1 parent a8ac198 commit 3b79779
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
8 changes: 8 additions & 0 deletions config/go.d/ping.conf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
# - 192.0.2.1
# - example.com
#
# - network
# Allows configuration of DNS resolution. Supported options:
# * "ip" will automatically select IPv4 or IPv6.
# * "ip4" will select IPv4.
# * "ip6" will select IPv6.
# Syntax:
# network: ip
#
# - privileged
# Sets the type of ping packets.
# "no" means send an "unprivileged" UDP ping. "yes" means send a "privileged" raw ICMP ping.
Expand Down
17 changes: 9 additions & 8 deletions modules/ping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ The following options can be defined globally: update_every, autodetection_retry
<details>
<summary>Config options</summary>

| Name | Description | Default | Required |
|:-------------------:|----------------------------------------------------------------------------------------|:-------:|:--------:|
| update_every | Data collection frequency. | 5 | |
| autodetection_retry | Re-check interval in seconds. Zero means not to schedule re-check. | 0 | |
| hosts | Network hosts. | | yes |
| privileged | Ping packets type. "no" means send an "unprivileged" UDP ping, "yes" - raw ICMP ping. | yes | |
| packets | Number of ping packets to send. | 5 | |
| interval | Timeout between sending ping packets. | 100ms | |
| Name | Description | Default | Required |
|:-------------------:|----------------------------------------------------------------------------------------------------------------------------|:-------:|:--------:|
| update_every | Data collection frequency. | 5 | |
| autodetection_retry | Re-check interval in seconds. Zero means not to schedule re-check. | 0 | |
| hosts | Network hosts. | | yes |
| network | Allows configuration of DNS resolution. Supported options: ip (select IPv4 or IPv6), ip4 (select IPv4), ip6 (select IPv6). | | |
| privileged | Ping packets type. "no" means send an "unprivileged" UDP ping, "yes" - raw ICMP ping. | yes | |
| packets | Number of ping packets to send. | 5 | |
| interval | Timeout between sending ping packets. | 100ms | |

</details>

Expand Down
4 changes: 4 additions & 0 deletions modules/ping/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ modules:
description: Network hosts.
default_value: ""
required: true
- name: network
description: "Allows configuration of DNS resolution. Supported options: ip (select IPv4 or IPv6), ip4 (select IPv4), ip6 (select IPv6)."
default_value: "ip"
required: false
- name: privileged
description: Ping packets type. "no" means send an "unprivileged" UDP ping, "yes" - raw ICMP ping.
default_value: true
Expand Down
20 changes: 10 additions & 10 deletions modules/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func init() {
func New() *Ping {
return &Ping{
Config: Config{
Network: "ip",
Privileged: true,
SendPackets: 5,
Interval: web.Duration{Duration: time.Millisecond * 100},
Expand All @@ -35,16 +36,15 @@ func New() *Ping {
}
}

type (
Config struct {
UpdateEvery int `yaml:"update_every"`
Hosts []string `yaml:"hosts"`
Privileged bool `yaml:"privileged"`
SendPackets int `yaml:"packets"`
Interval web.Duration `yaml:"interval"`
Interface string `yaml:"interface"`
}
)
type Config struct {
UpdateEvery int `yaml:"update_every"`
Hosts []string `yaml:"hosts"`
Network string `yaml:"network"`
Privileged bool `yaml:"privileged"`
SendPackets int `yaml:"packets"`
Interval web.Duration `yaml:"interval"`
Interface string `yaml:"interface"`
}

type (
Ping struct {
Expand Down
8 changes: 7 additions & 1 deletion modules/ping/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func newPingProber(conf pingProberConfig, log *logger.Logger) prober {
}

return &pingProber{
network: conf.network,
privileged: conf.privileged,
packets: conf.packets,
source: source,
Expand All @@ -35,6 +36,7 @@ func newPingProber(conf pingProberConfig, log *logger.Logger) prober {
}

type pingProberConfig struct {
network string
privileged bool
packets int
iface string
Expand All @@ -43,17 +45,21 @@ type pingProberConfig struct {
}

type pingProber struct {
*logger.Logger

network string
privileged bool
packets int
source string
interval time.Duration
deadline time.Duration
*logger.Logger
}

func (p *pingProber) ping(host string) (*probing.Statistics, error) {
pr := probing.New(host)

pr.SetNetwork(p.network)

if err := pr.Resolve(); err != nil {
return nil, fmt.Errorf("DNS lookup '%s' : %v", host, err)
}
Expand Down

0 comments on commit 3b79779

Please sign in to comment.