1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-11-08 05:50:06 +00:00

Deprecate parameter 'warn-only', update yaml unmarshal

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-04-27 11:55:43 +02:00
parent eaacc64f64
commit dc9c6bbc90
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

35
main.go
View file

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
@ -46,9 +45,10 @@ var (
)
type checkCommand struct {
Name string `yaml:"name"`
Command string `yaml:"command"`
WarnOnly bool `yaml:"warn-only"`
Name string `yaml:"name"`
Command string `yaml:"command"`
WarnOnly bool `yaml:"warn_only"`
WarnOnlyOld *bool `yaml:"warn-only"`
}
type checkResult struct {
@ -67,14 +67,16 @@ func init() {
}
func loadChecks() error {
var rawChecks []byte
var rawChecks io.Reader
if _, err := os.Stat(cfg.CheckDefinitionsFile); err == nil {
// We got a local file, read it
rawChecks, err = ioutil.ReadFile(cfg.CheckDefinitionsFile)
f, err := os.Open(cfg.CheckDefinitionsFile)
if err != nil {
return err
}
defer f.Close()
rawChecks = f
} else {
// Check whether we got an URL
if _, err := url.Parse(cfg.CheckDefinitionsFile); err != nil {
@ -87,20 +89,23 @@ func loadChecks() error {
return err
}
defer resp.Body.Close()
rawChecks, err = ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
rawChecks = resp.Body
}
tmpResult := map[string]checkCommand{}
err := yaml.Unmarshal(rawChecks, &tmpResult)
if err == nil {
checks = tmpResult
if err := yaml.NewDecoder(rawChecks).Decode(&tmpResult); err != nil {
return err
}
return err
for name, check := range tmpResult {
if check.WarnOnlyOld != nil {
log.Printf("Parameter 'warn-only' in check %q is deprecated: It's now named 'warn_only'", name)
check.WarnOnly = *check.WarnOnlyOld
}
}
checks = tmpResult
return nil
}
func main() {