blob: 62d78c8e6a0ef8da76d9fcbe984436ca0d0c5656 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// SPDX-License-Identifier: GPL-3.0-or-later
package ping
import (
"errors"
"time"
)
func (p *Ping) validateConfig() error {
if len(p.Hosts) == 0 {
return errors.New("'hosts' can't be empty")
}
if p.SendPackets <= 0 {
return errors.New("'send_packets' can't be <= 0")
}
return nil
}
func (p *Ping) initProber() (prober, error) {
mul := 0.9
if p.UpdateEvery > 1 {
mul = 0.95
}
deadline := time.Millisecond * time.Duration(float64(p.UpdateEvery)*mul*1000)
if deadline.Milliseconds() == 0 {
return nil, errors.New("zero ping deadline")
}
conf := pingProberConfig{
privileged: p.Privileged,
packets: p.SendPackets,
iface: p.Interface,
interval: p.Interval.Duration(),
deadline: deadline,
}
return p.newProber(conf, p.Logger), nil
}
|