1 diff --git a/internal/config/config.go b/internal/config/config.go
2 index ba8f066..1c801cd 100644
3 --- a/internal/config/config.go
4 +++ b/internal/config/config.go
5 @@ -2,8 +2,11 @@ package config
14 "github.com/mrlhansen/idrac_exporter/internal/logging"
17 @@ -17,9 +20,9 @@ type HostConfig struct {
19 type RootConfig struct {
21 - Address string `yaml:"address"`
22 - Port uint `yaml:"port"`
23 - MetricsPrefix string `yaml:"metrics_prefix"`
24 + Address string `yaml:"address"`
25 + Port uint `yaml:"port"`
26 + MetricsPrefix string `yaml:"metrics_prefix"`
28 System bool `yaml:"system"`
29 Sensors bool `yaml:"sensors"`
30 @@ -28,9 +31,29 @@ type RootConfig struct {
31 Storage bool `yaml:"storage"`
32 Memory bool `yaml:"memory"`
34 - Timeout uint `yaml:"timeout"`
35 - Retries uint `yaml:"retries"`
36 - Hosts map[string]*HostConfig `yaml:"hosts"`
37 + Timeout uint `yaml:"timeout"`
38 + Retries uint `yaml:"retries"`
39 + Hosts map[string]*HostConfig `yaml:"hosts"`
42 +func getEnv(envvar string, defvalue string) string {
43 + value := os.Getenv(envvar)
44 + if len(value) == 0 {
50 +func getEnvUint(envvar string, defvalue uint) uint {
51 + value, err := strconv.Atoi(getEnv(envvar, fmt.Sprint(defvalue)))
53 + logging.Fatalf("Failed parse integer value: %s", err)
62 func (config *RootConfig) GetHostCfg(target string) *HostConfig {
63 @@ -70,29 +93,29 @@ func ReadConfigFile(fileName string) {
66 if Config.Address == "" {
67 - Config.Address = "0.0.0.0"
68 + Config.Address = getEnv("IDRAC_EXPORTER_LISTEN_ADDRESS", "0.0.0.0")
73 + Config.Port = getEnvUint("IDRAC_EXPORTER_LISTEN_PORT", 9348)
76 if Config.Timeout == 0 {
78 + Config.Timeout = getEnvUint("IDRAC_EXPORTER_TIMEOUT", 10)
81 if Config.Retries == 0 {
83 + Config.Retries = getEnvUint("IDRAC_EXPORTER_RETRIES", 1)
86 + if Config.MetricsPrefix == "" {
87 + Config.MetricsPrefix = getEnv("IDRAC_EXPORTER_PREFIX", "idrac")
90 if len(Config.Hosts) == 0 {
91 parseError("missing section", "hosts")
94 - if Config.MetricsPrefix == "" {
95 - Config.MetricsPrefix = "idrac"
98 for k, v := range Config.Hosts {
100 parseError("missing username for host", k)