示例#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)
}
示例#2
0
文件: mode_test.go 项目: jarpy/beats
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)
}
示例#3
0
文件: cfgfile.go 项目: jarpy/beats
// 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
}
示例#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)
}
示例#5
0
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
}
示例#6
0
文件: config.go 项目: McStork/beats
func (c *Config) SetChild(name string, idx int, value *Config) error {
	return c.access().SetChild(name, idx, value.access(), ucfg.PathSep("."))
}
示例#7
0
文件: config.go 项目: McStork/beats
func (c *Config) Bool(name string, idx int) (bool, error) {
	return c.access().Bool(name, idx, ucfg.PathSep("."))
}
示例#8
0
文件: config.go 项目: McStork/beats
func (c *Config) SetFloat(name string, idx int, value float64) error {
	return c.access().SetFloat(name, idx, value, ucfg.PathSep("."))
}
示例#9
0
文件: config.go 项目: McStork/beats
func (c *Config) SetString(name string, idx int, value string) error {
	return c.access().SetString(name, idx, value, ucfg.PathSep("."))
}
示例#10
0
文件: config.go 项目: McStork/beats
func (c *Config) Float(name string, idx int) (float64, error) {
	return c.access().Float(name, idx, ucfg.PathSep("."))
}
示例#11
0
文件: config.go 项目: McStork/beats
func (c *Config) Child(name string, idx int) (*Config, error) {
	sub, err := c.access().Child(name, idx, ucfg.PathSep("."))
	return fromConfig(sub), err
}
示例#12
0
文件: config.go 项目: McStork/beats
func (c *Config) String(name string, idx int) (string, error) {
	return c.access().String(name, idx, ucfg.PathSep("."))
}
示例#13
0
文件: config.go 项目: McStork/beats
func (c *Config) Int(name string, idx int) (int64, error) {
	return c.access().Int(name, idx, ucfg.PathSep("."))
}
示例#14
0
文件: config.go 项目: McStork/beats
func NewConfigFrom(from interface{}) (*Config, error) {
	c, err := ucfg.NewFrom(from, ucfg.PathSep("."))
	return fromConfig(c), err
}
示例#15
0
文件: config.go 项目: McStork/beats
func (c *Config) Unpack(to interface{}) error {
	return c.access().Unpack(to, ucfg.PathSep("."))
}
示例#16
0
文件: config.go 项目: McStork/beats
func (c *Config) Merge(from interface{}) error {
	return c.access().Merge(from, ucfg.PathSep("."))
}
示例#17
0
文件: config.go 项目: McStork/beats
func LoadFile(path string) (*Config, error) {
	c, err := yaml.NewConfigWithFile(path, ucfg.PathSep("."))
	return fromConfig(c), err
}
示例#18
0
文件: config.go 项目: McStork/beats
func NewConfigWithYAML(in []byte, source string) (*Config, error) {
	c, err := yaml.NewConfig(in, ucfg.PathSep("."), ucfg.MetaData(ucfg.Meta{source}))
	return fromConfig(c), err
}