http-server-status/config.go

49 lines
1 KiB
Go
Raw Normal View History

2021-09-20 10:38:41 +00:00
package main
import (
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v2"
"http-server-status/internal/pkg/checks"
"io/ioutil"
"os"
)
var c Config
type Config struct {
HTTP struct{
Listen string `yaml:"listen"`
} `yaml:"http"`
2021-11-29 04:53:12 +00:00
Auth struct{
Enabled bool `yaml:"enabled"`
Username string `yaml:"username"`
Password string `yaml:"password"`
} `yaml:"auth"`
2021-09-20 10:38:41 +00:00
Checks struct{
HDD checks.HDDConfig `yaml:"hdd"`
Load checks.LoadConfig `yaml:"load"`
Memory checks.MemoryConfig `yaml:"memory"`
2021-10-21 10:15:55 +00:00
Systemd checks.SystemdConf `yaml:"systemd"`
2021-11-29 06:31:30 +00:00
Version checks.VersionConfig `yaml:"version"`
2021-09-20 10:38:41 +00:00
} `yaml:"checks"`
}
func readConfig() {
filename := "/etc/http-server-status/config.yml"
if len(os.Args) > 1 {
filename = os.Args[1]
}
log.Debug().Str("filename", filename).Msg("Load Config")
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal().Err(err).Msg("Cant get config file")
}
err = yaml.Unmarshal(yamlFile, &c)
if err != nil {
log.Fatal().Err(err).Msg("Cant parse yaml file")
}
2021-11-29 06:31:30 +00:00
c.Checks.Version.Version = version
2021-09-20 10:38:41 +00:00
}