-
-
Notifications
You must be signed in to change notification settings - Fork 588
/
mon_conf.go
60 lines (52 loc) · 1.31 KB
/
mon_conf.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package observer
import (
"fmt"
"strings"
"github.com/letsencrypt/boulder/cmd"
p "github.com/letsencrypt/boulder/observer/probes"
"gopkg.in/yaml.v2"
)
type settings map[string]interface{}
// MonConf is exported to receive yaml configuration
type MonConf struct {
Valid bool
Period cmd.ConfigDuration `yaml:"period"`
Timeout int `yaml:"timeout"`
Kind string `yaml:"type"`
Settings settings `yaml:"settings"`
}
func (c MonConf) normalize() {
c.Kind = strings.ToLower(c.Kind)
}
func (c MonConf) unmashalProbeSettings() (p.Configurer, error) {
probeConf, err := p.GetProbeConf(c.Kind, c.Settings)
if err != nil {
return nil, err
}
s, _ := yaml.Marshal(c.Settings)
probeConf, err = probeConf.UnmarshalSettings(s)
if err != nil {
return nil, err
}
return probeConf, nil
}
// validate normalizes and validates the received monitor config
func (c *MonConf) validate() error {
c.normalize()
probeConf, err := c.unmashalProbeSettings()
if err != nil {
return err
}
err = probeConf.Validate()
if err != nil {
return fmt.Errorf(
"failed to validate: %s prober with settings: %+v due to: %w",
c.Kind, probeConf, err)
}
c.Valid = true
return nil
}
func (c MonConf) getProber() p.Prober {
probeConf, _ := c.unmashalProbeSettings()
return probeConf.AsProbe()
}