From 234ad3c54e373c9bfc45fb8deb8f801a07965746 Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Thu, 17 Nov 2022 11:33:13 +0100 Subject: [PATCH] Fix kernel panic for receiver config with missing receiver type --- receivers/receiveManager.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/receivers/receiveManager.go b/receivers/receiveManager.go index c47c3cc..067a179 100644 --- a/receivers/receiveManager.go +++ b/receivers/receiveManager.go @@ -2,6 +2,7 @@ package receivers import ( "encoding/json" + "fmt" "os" "sync" @@ -71,9 +72,13 @@ func (rm *receiveManager) AddInput(name string, rawConfig json.RawMessage) error cclog.ComponentError("ReceiveManager", "SKIP", config.Type, "JSON config error:", err.Error()) return err } + if config.Type == "" { + cclog.ComponentError("ReceiveManager", "SKIP", "JSON config for receiver", name, "does not contain a receiver type") + return fmt.Errorf("JSON config for receiver %s does not contain a receiver type", name) + } if _, found := AvailableReceivers[config.Type]; !found { - cclog.ComponentError("ReceiveManager", "SKIP", config.Type, "unknown receiver:", err.Error()) - return err + cclog.ComponentError("ReceiveManager", "SKIP", "unknown receiver type:", config.Type) + return fmt.Errorf("unknown receiver type: %s", config.Type) } r, err := AvailableReceivers[config.Type](name, rawConfig) if err != nil {