Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check validity of logstash module configuration when xpack.enabled is set to true #12670

Merged
merged 1 commit into from
Jun 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions metricbeat/module/logstash/logstash.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,54 @@ import (

"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/helper"
"github.com/elastic/beats/metricbeat/mb"
)

func init() {
// Register the ModuleFactory function for this module.
if err := mb.Registry.AddModule(ModuleName, NewModule); err != nil {
panic(err)
}
}

// NewModule creates a new module after performing validation.
func NewModule(base mb.BaseModule) (mb.Module, error) {
if err := validateXPackMetricsets(base); err != nil {
return nil, err
}

return &base, nil
}

// Validate that correct metricsets have been specified if xpack.enabled = true.
func validateXPackMetricsets(base mb.BaseModule) error {
config := struct {
Metricsets []string `config:"metricsets"`
XPackEnabled bool `config:"xpack.enabled"`
}{}
if err := base.UnpackConfig(&config); err != nil {
return err
}

// Nothing to validate if xpack.enabled != true
if !config.XPackEnabled {
return nil
}

expectedXPackMetricsets := []string{
"node",
"node_stats",
}

if !common.MakeStringSet(config.Metricsets...).Equals(common.MakeStringSet(expectedXPackMetricsets...)) {
return errors.Errorf("The %v module with xpack.enabled: true must have metricsets: %v", ModuleName, expectedXPackMetricsets)
}

return nil
}

// ModuleName is the name of this module.
const ModuleName = "logstash"

Expand Down