| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package pinger |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "time" |
| 8 | |
| 9 | "github.com/netdata/netdata/go/plugins/pkg/confopt" |
| 10 | ) |
| 11 | |
| 12 | const ( |
| 13 | defaultJitterEWMASamples = 16 |
| 14 | defaultJitterSMAWindow = 10 |
| 15 | ) |
| 16 | |
| 17 | type ProbeConfig struct { |
| 18 | Network string `yaml:"network,omitempty" json:"network"` |
| 19 | Interface string `yaml:"interface,omitempty" json:"interface"` |
| 20 | Privileged bool `yaml:"privileged" json:"privileged"` |
| 21 | Packets int `yaml:"packets,omitempty" json:"packets"` |
| 22 | Interval confopt.Duration `yaml:"interval,omitempty" json:"interval"` |
| 23 | Timeout time.Duration `yaml:"-,omitempty" json:",omitempty"` |
| 24 | } |
| 25 | |
| 26 | type AnalysisConfig struct { |
| 27 | JitterEWMASamples int `yaml:"jitter_ewma_samples,omitempty" json:"jitter_ewma_samples"` |
| 28 | JitterSMAWindow int `yaml:"jitter_sma_window,omitempty" json:"jitter_sma_window"` |
| 29 | } |
| 30 | |
| 31 | type Config struct { |
| 32 | Probe ProbeConfig |
| 33 | Analysis AnalysisConfig |
| 34 | } |
| 35 | |
| 36 | func normalizeConfig(cfg Config) (Config, error) { |
| 37 | if cfg.Probe.Packets <= 0 { |
| 38 | return Config{}, errors.New("probe packets must be > 0") |
| 39 | } |
| 40 | if cfg.Probe.Interval.Duration() <= 0 { |
| 41 | return Config{}, errors.New("probe interval must be > 0") |
| 42 | } |
| 43 | if cfg.Probe.Timeout <= 0 { |
| 44 | return Config{}, errors.New("probe timeout must be > 0") |
| 45 | } |
| 46 | |
| 47 | if cfg.Analysis.JitterEWMASamples <= 0 { |
| 48 | cfg.Analysis.JitterEWMASamples = defaultJitterEWMASamples |
| 49 | } |
| 50 | if cfg.Analysis.JitterSMAWindow <= 0 { |
| 51 | cfg.Analysis.JitterSMAWindow = defaultJitterSMAWindow |
| 52 | } |
| 53 | |
| 54 | return cfg, nil |
| 55 | } |