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) }
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) }
// 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 }
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 }
func (c *Config) SetChild(name string, idx int, value *Config) error { return c.access().SetChild(name, idx, value.access(), ucfg.PathSep(".")) }
func (c *Config) Bool(name string, idx int) (bool, error) { return c.access().Bool(name, idx, ucfg.PathSep(".")) }
func (c *Config) SetFloat(name string, idx int, value float64) error { return c.access().SetFloat(name, idx, value, ucfg.PathSep(".")) }
func (c *Config) SetString(name string, idx int, value string) error { return c.access().SetString(name, idx, value, ucfg.PathSep(".")) }
func (c *Config) Float(name string, idx int) (float64, error) { return c.access().Float(name, idx, ucfg.PathSep(".")) }
func (c *Config) Child(name string, idx int) (*Config, error) { sub, err := c.access().Child(name, idx, ucfg.PathSep(".")) return fromConfig(sub), err }
func (c *Config) String(name string, idx int) (string, error) { return c.access().String(name, idx, ucfg.PathSep(".")) }
func (c *Config) Int(name string, idx int) (int64, error) { return c.access().Int(name, idx, ucfg.PathSep(".")) }
func NewConfigFrom(from interface{}) (*Config, error) { c, err := ucfg.NewFrom(from, ucfg.PathSep(".")) return fromConfig(c), err }
func (c *Config) Unpack(to interface{}) error { return c.access().Unpack(to, ucfg.PathSep(".")) }
func (c *Config) Merge(from interface{}) error { return c.access().Merge(from, ucfg.PathSep(".")) }
func LoadFile(path string) (*Config, error) { c, err := yaml.NewConfigWithFile(path, ucfg.PathSep(".")) return fromConfig(c), err }
func NewConfigWithYAML(in []byte, source string) (*Config, error) { c, err := yaml.NewConfig(in, ucfg.PathSep("."), ucfg.MetaData(ucfg.Meta{source})) return fromConfig(c), err }