From ffd32b8630253794a9c547ac0ce6d230ef6f4391 Mon Sep 17 00:00:00 2001 From: "yufu.deng" <954068039@qq.com> Date: Tue, 14 Jun 2022 17:26:45 +0800 Subject: [PATCH] ignore init fail input option (#1) * add ignore_init_fail_input option for ignore initialization failed Input #11289 #10694 * rename option ignore_init_fail_input to ignore_error_inputs --- agent/agent.go | 8 +++++++- config/config.go | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index ffa5d6bd06425..8b0b0bf5071da 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -186,17 +186,23 @@ func (a *Agent) Run(ctx context.Context) error { // initPlugins runs the Init function on plugins. func (a *Agent) initPlugins() error { + inputs := make([]*models.RunningInput, 0) for _, input := range a.Config.Inputs { // Share the snmp translator setting with plugins that need it. if tp, ok := input.Input.(snmp.TranslatorPlugin); ok { tp.SetTranslator(a.Config.Agent.SnmpTranslator) } err := input.Init() - if err != nil { + if err != nil && a.Config.Agent.IgnoreErrorInputs { + log.Printf("W! [agent] Ignore initialize error input %s: %v", input.LogName(), err) + continue + } else if err != nil { return fmt.Errorf("could not initialize input %s: %v", input.LogName(), err) } + inputs = append(inputs, input) } + a.Config.Inputs = inputs for _, parser := range a.Config.Parsers { err := parser.Init() if err != nil { diff --git a/config/config.go b/config/config.go index 3f291a9030688..9f9b41e39ff6d 100644 --- a/config/config.go +++ b/config/config.go @@ -223,6 +223,9 @@ type AgentConfig struct { // Pick a timezone to use when logging or type 'local' for local time. LogWithTimezone string `toml:"log_with_timezone"` + // Ignore Inputs that error to initialize + IgnoreErrorInputs bool `toml:"ignore_error_inputs"` + Hostname string OmitHostname bool