1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-11-08 14:00:09 +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" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
@ -46,9 +45,10 @@ var (
) )
type checkCommand struct { type checkCommand struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Command string `yaml:"command"` Command string `yaml:"command"`
WarnOnly bool `yaml:"warn-only"` WarnOnly bool `yaml:"warn_only"`
WarnOnlyOld *bool `yaml:"warn-only"`
} }
type checkResult struct { type checkResult struct {
@ -67,14 +67,16 @@ func init() {
} }
func loadChecks() error { func loadChecks() error {
var rawChecks []byte var rawChecks io.Reader
if _, err := os.Stat(cfg.CheckDefinitionsFile); err == nil { if _, err := os.Stat(cfg.CheckDefinitionsFile); err == nil {
// We got a local file, read it // We got a local file, read it
rawChecks, err = ioutil.ReadFile(cfg.CheckDefinitionsFile) f, err := os.Open(cfg.CheckDefinitionsFile)
if err != nil { if err != nil {
return err return err
} }
defer f.Close()
rawChecks = f
} else { } else {
// Check whether we got an URL // Check whether we got an URL
if _, err := url.Parse(cfg.CheckDefinitionsFile); err != nil { if _, err := url.Parse(cfg.CheckDefinitionsFile); err != nil {
@ -87,20 +89,23 @@ func loadChecks() error {
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
rawChecks, err = ioutil.ReadAll(resp.Body) rawChecks = resp.Body
if err != nil {
return err
}
} }
tmpResult := map[string]checkCommand{} tmpResult := map[string]checkCommand{}
err := yaml.Unmarshal(rawChecks, &tmpResult) if err := yaml.NewDecoder(rawChecks).Decode(&tmpResult); err != nil {
return err
if err == nil {
checks = tmpResult
} }
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() { func main() {