...
1 package observer
2
3 import (
4 "errors"
5 "time"
6
7 "github.com/prometheus/client_golang/prometheus"
8 "gopkg.in/yaml.v3"
9
10 "github.com/letsencrypt/boulder/config"
11 "github.com/letsencrypt/boulder/observer/probers"
12 )
13
14
15 type MonConf struct {
16 Period config.Duration `yaml:"period"`
17 Kind string `yaml:"kind" validate:"required,oneof=DNS HTTP CRL TLS"`
18 Settings probers.Settings `yaml:"settings" validate:"min=1,dive"`
19 }
20
21
22 func (c *MonConf) validatePeriod() error {
23 if c.Period.Duration < 1*time.Microsecond {
24 return errors.New("period must be at least 1µs")
25 }
26 return nil
27 }
28
29
30
31
32
33 func (c MonConf) unmarshalConfigurer() (probers.Configurer, error) {
34 configurer, err := probers.GetConfigurer(c.Kind)
35 if err != nil {
36 return nil, err
37 }
38 settings, _ := yaml.Marshal(c.Settings)
39 configurer, err = configurer.UnmarshalSettings(settings)
40 if err != nil {
41 return nil, err
42 }
43 return configurer, nil
44 }
45
46
47
48
49 func (c MonConf) makeMonitor(collectors map[string]prometheus.Collector) (*monitor, error) {
50 err := c.validatePeriod()
51 if err != nil {
52 return nil, err
53 }
54 probeConf, err := c.unmarshalConfigurer()
55 if err != nil {
56 return nil, err
57 }
58 prober, err := probeConf.MakeProber(collectors)
59 if err != nil {
60 return nil, err
61 }
62 return &monitor{c.Period.Duration, prober}, nil
63 }
64
View as plain text