Fix kernel panic for receiver config with missing receiver type

This commit is contained in:
Holger Obermaier 2022-11-17 11:33:13 +01:00
parent 7bb80780e0
commit 234ad3c54e

View File

@ -2,6 +2,7 @@ package receivers
import ( import (
"encoding/json" "encoding/json"
"fmt"
"os" "os"
"sync" "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()) cclog.ComponentError("ReceiveManager", "SKIP", config.Type, "JSON config error:", err.Error())
return err 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 { if _, found := AvailableReceivers[config.Type]; !found {
cclog.ComponentError("ReceiveManager", "SKIP", config.Type, "unknown receiver:", err.Error()) cclog.ComponentError("ReceiveManager", "SKIP", "unknown receiver type:", config.Type)
return err return fmt.Errorf("unknown receiver type: %s", config.Type)
} }
r, err := AvailableReceivers[config.Type](name, rawConfig) r, err := AvailableReceivers[config.Type](name, rawConfig)
if err != nil { if err != nil {