Exemple #1
0
func newTestLumberjackOutput(
	t *testing.T,
	test string,
	config map[string]interface{},
) outputs.BulkOutputer {
	if config == nil {
		config = map[string]interface{}{
			"hosts": []string{getLogstashHost()},
			"index": testLogstashIndex(test),
		}
	}

	plugin := outputs.FindOutputPlugin("logstash")
	if plugin == nil {
		t.Fatalf("No logstash output plugin found")
	}

	cfg, _ := ucfg.NewFrom(config, ucfg.PathSep("."))
	output, err := plugin(cfg, 0)
	if err != nil {
		t.Fatalf("init logstash output plugin failed: %v", err)
	}

	return output.(outputs.BulkOutputer)
}
Exemple #2
0
func makeTestClients(c map[string]interface{},
	newClient func(string) (ProtocolClient, error),
) ([]ProtocolClient, error) {
	cfg, err := ucfg.NewFrom(c, ucfg.PathSep("."))
	if err != nil {
		return nil, err
	}

	return MakeClients(cfg, newClient)
}
Exemple #3
0
// Read reads the configuration from a yaml file into the given interface structure.
// In case path is not set this method reads from the default configuration file for the beat.
func Read(out interface{}, path string) error {

	if path == "" {
		path = *configfile
	}

	filecontent, err := ioutil.ReadFile(path)
	if err != nil {
		return fmt.Errorf("Failed to read %s: %v. Exiting.", path, err)
	}
	filecontent = expandEnv(filecontent)

	config, err := yaml.NewConfig(filecontent, ucfg.PathSep("."))
	if err != nil {
		return fmt.Errorf("YAML config parsing failed on %s: %v. Exiting.", path, err)
	}

	err = config.Unpack(out, ucfg.PathSep("."))
	if err != nil {
		return fmt.Errorf("Failed to apply config %s: %v. Exiting. ", path, err)
	}
	return nil
}
Exemple #4
0
func TestNestedPath(t *testing.T) {
	input := []byte(`
    c.b: true
  `)

	c, err := NewConfig(input, ucfg.PathSep("."))
	if err != nil {
		t.Fatalf("failed to parse input: %v", err)
	}

	var verify struct {
		C struct{ B bool }
	}
	err = c.Unpack(&verify)
	assert.NoError(t, err)
	assert.True(t, verify.C.B)
}
func newTestKafkaOutput(t *testing.T, topic string, useType bool) outputs.Outputer {

	config := map[string]interface{}{
		"hosts":          []string{getTestKafkaHost()},
		"broker_timeout": "1s",
		"timeout":        1,
		"topic":          topic,
		"use_type":       useType,
	}

	cfg, err := ucfg.NewFrom(config, ucfg.PathSep("."))
	assert.NoError(t, err)
	output, err := New(cfg, 0)
	assert.NoError(t, err)

	return output
}
Exemple #6
0
func (c *Config) SetChild(name string, idx int, value *Config) error {
	return c.access().SetChild(name, idx, value.access(), ucfg.PathSep("."))
}
Exemple #7
0
func (c *Config) Bool(name string, idx int) (bool, error) {
	return c.access().Bool(name, idx, ucfg.PathSep("."))
}
Exemple #8
0
func (c *Config) SetFloat(name string, idx int, value float64) error {
	return c.access().SetFloat(name, idx, value, ucfg.PathSep("."))
}
Exemple #9
0
func (c *Config) SetString(name string, idx int, value string) error {
	return c.access().SetString(name, idx, value, ucfg.PathSep("."))
}
Exemple #10
0
func (c *Config) Float(name string, idx int) (float64, error) {
	return c.access().Float(name, idx, ucfg.PathSep("."))
}
Exemple #11
0
func (c *Config) Child(name string, idx int) (*Config, error) {
	sub, err := c.access().Child(name, idx, ucfg.PathSep("."))
	return fromConfig(sub), err
}
Exemple #12
0
func (c *Config) String(name string, idx int) (string, error) {
	return c.access().String(name, idx, ucfg.PathSep("."))
}
Exemple #13
0
func (c *Config) Int(name string, idx int) (int64, error) {
	return c.access().Int(name, idx, ucfg.PathSep("."))
}
Exemple #14
0
func NewConfigFrom(from interface{}) (*Config, error) {
	c, err := ucfg.NewFrom(from, ucfg.PathSep("."))
	return fromConfig(c), err
}
Exemple #15
0
func (c *Config) Unpack(to interface{}) error {
	return c.access().Unpack(to, ucfg.PathSep("."))
}
Exemple #16
0
func (c *Config) Merge(from interface{}) error {
	return c.access().Merge(from, ucfg.PathSep("."))
}
Exemple #17
0
func LoadFile(path string) (*Config, error) {
	c, err := yaml.NewConfigWithFile(path, ucfg.PathSep("."))
	return fromConfig(c), err
}
Exemple #18
0
func NewConfigWithYAML(in []byte, source string) (*Config, error) {
	c, err := yaml.NewConfig(in, ucfg.PathSep("."), ucfg.MetaData(ucfg.Meta{source}))
	return fromConfig(c), err
}