Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2688b1
commit 9b0c800
Showing
22 changed files
with
755 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,63 @@ | ||
package observer | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/letsencrypt/boulder/observer/plugins" | ||
"github.com/letsencrypt/boulder/cmd" | ||
p "github.com/letsencrypt/boulder/observer/probes" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
var ( | ||
errNewMonEmpty = errors.New("monitor config is empty") | ||
errNewMonInvalid = errors.New("monitor config is invalid") | ||
) | ||
type settings map[string]interface{} | ||
|
||
// MonConf is exported to receive the supplied monitor config | ||
// MonConf is exported to receive yaml configuration | ||
type MonConf struct { | ||
Enabled bool `yaml:"enabled"` | ||
Period int `yaml:"period"` | ||
Timeout int `yaml:"timeout"` | ||
Plugin plugins.Info `yaml:"plugin"` | ||
Settings map[string]interface{} `yaml:"settings"` | ||
Valid bool | ||
Period cmd.ConfigDuration `yaml:"period"` | ||
Timeout int `yaml:"timeout"` | ||
Probe string `yaml:"type"` | ||
Settings settings `yaml:"settings"` | ||
} | ||
|
||
func (c MonConf) normalize() { | ||
c.Plugin.Name = strings.ToLower(c.Plugin.Name) | ||
c.Plugin.Path = strings.ToLower(c.Plugin.Path) | ||
c.Probe = strings.ToLower(c.Probe) | ||
} | ||
|
||
func (c MonConf) unmashalProbeSettings() (p.Configurer, error) { | ||
probeConf, err := p.GetProbeConf(c.Probe, 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 { | ||
func (c *MonConf) validate() error { | ||
c.normalize() | ||
pluginConf, err := plugins.GetPluginConf(c.Settings, c.Plugin.Path, c.Plugin.Name) | ||
probeConf, err := c.unmashalProbeSettings() | ||
if err != nil { | ||
if err != nil { | ||
return fmt.Errorf("failed to get plugin: %w", err) | ||
} | ||
return err | ||
} | ||
err = pluginConf.Validate() | ||
err = probeConf.Validate() | ||
if err != nil { | ||
return fmt.Errorf("failed to validate plugin settings: %w", err) | ||
return fmt.Errorf("failed to validate probe: %s with settings: %+v due to: %w", c.Probe, probeConf, err) | ||
} | ||
c.Valid = true | ||
return nil | ||
} | ||
|
||
func (c MonConf) getProber() p.Prober { | ||
probeConf, _ := c.unmashalProbeSettings() | ||
return probeConf.AsProbe() | ||
} | ||
|
||
func (c MonConf) getName() string { | ||
probeConf, _ := c.unmashalProbeSettings() | ||
return probeConf.GetMonitorName() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.