From 604dcf355ce387de5b5030473163838c5855fa31 Mon Sep 17 00:00:00 2001 From: Martin Kleine <24376955+datenzar@users.noreply.github.com> Date: Sat, 30 Mar 2024 09:20:57 +0100 Subject: [PATCH 1/2] feat: Ability to override commands args In order to override the arguments which are used e.g. to call smartctl, they need to be bind to the respective environment variable. --- collector/pkg/config/config.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/collector/pkg/config/config.go b/collector/pkg/config/config.go index 45bb3b8..dccef90 100644 --- a/collector/pkg/config/config.go +++ b/collector/pkg/config/config.go @@ -48,6 +48,16 @@ func (c *configuration) Init() error { c.SetDefault("commands.metrics_info_args", "--info --json") c.SetDefault("commands.metrics_smart_args", "--xall --json") + // Bind environment variables with COLLECTOR_ prefix + c.BindEnv("host.id", "COLLECTOR_HOST_ID") + c.BindEnv("log.level", "COLLECTOR_LOG_LEVEL") + c.BindEnv("log.file", "COLLECTOR_LOG_FILE") + c.BindEnv("api.endpoint", "COLLECTOR_API_ENDPOINT") + c.BindEnv("commands.metrics_smartctl_bin", "COLLECTOR_COMMANDS_METRICS_SMARTCTL_BIN") + c.BindEnv("commands.metrics_scan_args", "COLLECTOR_COMMANDS_METRICS_SCAN_ARGS") + c.BindEnv("commands.metrics_info_args", "COLLECTOR_COMMANDS_METRICS_INFO_ARGS") + c.BindEnv("commands.metrics_smart_args", "COLLECTOR_COMMANDS_METRICS_SMART_ARGS") + //c.SetDefault("collect.short.command", "-a -o on -S on") c.SetDefault("allow_listed_devices", []string{}) From a783604c4e5ce3c286bc9f2d5c576b27a9ce820e Mon Sep 17 00:00:00 2001 From: Martin Kleine <24376955+datenzar@users.noreply.github.com> Date: Tue, 15 Oct 2024 00:14:06 +0200 Subject: [PATCH 2/2] Feature: Use automatic binding of env variables --- collector/pkg/config/config.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/collector/pkg/config/config.go b/collector/pkg/config/config.go index dccef90..501a89c 100644 --- a/collector/pkg/config/config.go +++ b/collector/pkg/config/config.go @@ -48,15 +48,10 @@ func (c *configuration) Init() error { c.SetDefault("commands.metrics_info_args", "--info --json") c.SetDefault("commands.metrics_smart_args", "--xall --json") - // Bind environment variables with COLLECTOR_ prefix - c.BindEnv("host.id", "COLLECTOR_HOST_ID") - c.BindEnv("log.level", "COLLECTOR_LOG_LEVEL") - c.BindEnv("log.file", "COLLECTOR_LOG_FILE") - c.BindEnv("api.endpoint", "COLLECTOR_API_ENDPOINT") - c.BindEnv("commands.metrics_smartctl_bin", "COLLECTOR_COMMANDS_METRICS_SMARTCTL_BIN") - c.BindEnv("commands.metrics_scan_args", "COLLECTOR_COMMANDS_METRICS_SCAN_ARGS") - c.BindEnv("commands.metrics_info_args", "COLLECTOR_COMMANDS_METRICS_INFO_ARGS") - c.BindEnv("commands.metrics_smart_args", "COLLECTOR_COMMANDS_METRICS_SMART_ARGS") + //configure env variable parsing. + c.SetEnvPrefix("COLLECTOR") + c.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_")) + c.AutomaticEnv() //c.SetDefault("collect.short.command", "-a -o on -S on")