2019-09-21 22:03:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
CheckInterval int64 `yaml:"check_interval"`
|
2019-10-02 16:37:29 +00:00
|
|
|
Monitors []*Monitor
|
|
|
|
Alerts map[string]*Alert
|
2019-09-21 22:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfig(filePath string) (config Config) {
|
|
|
|
data, err := ioutil.ReadFile(filePath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-10-01 15:26:07 +00:00
|
|
|
|
|
|
|
// TODO: Decide if this is better expanded here, or only when executing
|
2019-09-21 22:03:26 +00:00
|
|
|
env_expanded := os.ExpandEnv(string(data))
|
|
|
|
|
|
|
|
err = yaml.Unmarshal([]byte(env_expanded), &config)
|
|
|
|
if err != nil {
|
2019-10-02 16:37:29 +00:00
|
|
|
log.Fatalf("ERROR: %v", err)
|
2019-09-21 22:03:26 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("config:\n%v\n", config)
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|