Fix crash caused by:

* not running a collector manager when collector manager config file is missing
* not running a metric router when metric router config file is missing
* not running a sink manager when sink manager config file is missing
This commit is contained in:
Holger Obermaier 2022-01-28 19:49:46 +01:00
parent d2e02ed36d
commit 7316de2813

View File

@ -211,6 +211,21 @@ func mainFunc() int {
}
rcfg.Duration = time.Duration(rcfg.ConfigFile.Duration) * time.Second
if len(rcfg.ConfigFile.RouterConfigFile) == 0 {
cclog.Error("Metric router configuration file must be set")
return 1
}
if len(rcfg.ConfigFile.SinkConfigFile) == 0 {
cclog.Error("Sink configuration file must be set")
return 1
}
if len(rcfg.ConfigFile.CollectorConfigFile) == 0 {
cclog.Error("Metric collector configuration file must be set")
return 1
}
// err = CreatePidfile(rcfg.CliArgs["pidfile"])
// Set log file
@ -222,16 +237,13 @@ func mainFunc() int {
rcfg.MultiChanTicker = mct.NewTicker(rcfg.Interval)
// Create new metric router
if len(rcfg.ConfigFile.RouterConfigFile) > 0 {
rcfg.MetricRouter, err = mr.New(rcfg.MultiChanTicker, &rcfg.Sync, rcfg.ConfigFile.RouterConfigFile)
if err != nil {
cclog.Error(err.Error())
return 1
}
}
// Create new sink
if len(rcfg.ConfigFile.SinkConfigFile) > 0 {
rcfg.SinkManager, err = sinks.New(&rcfg.Sync, rcfg.ConfigFile.SinkConfigFile)
if err != nil {
cclog.Error(err.Error())
@ -242,10 +254,8 @@ func mainFunc() int {
RouterToSinksChannel := make(chan lp.CCMetric, 200)
rcfg.SinkManager.AddInput(RouterToSinksChannel)
rcfg.MetricRouter.AddOutput(RouterToSinksChannel)
}
// Create new collector manager
if len(rcfg.ConfigFile.CollectorConfigFile) > 0 {
rcfg.CollectManager, err = collectors.New(rcfg.MultiChanTicker, rcfg.Duration, &rcfg.Sync, rcfg.ConfigFile.CollectorConfigFile)
if err != nil {
cclog.Error(err.Error())
@ -256,7 +266,6 @@ func mainFunc() int {
CollectToRouterChannel := make(chan lp.CCMetric, 200)
rcfg.CollectManager.AddOutput(CollectToRouterChannel)
rcfg.MetricRouter.AddCollectorInput(CollectToRouterChannel)
}
// Create new receive manager
if len(rcfg.ConfigFile.ReceiverConfigFile) > 0 {