本文整理汇总了Golang中github.com/elastic/beats/libbeat/common.NewConfigFrom函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConfigFrom函数的具体用法?Golang NewConfigFrom怎么用?Golang NewConfigFrom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewConfigFrom函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: connectTestEs
func connectTestEs(t *testing.T, cfg interface{}) (outputs.BulkOutputer, *Client) {
config, err := common.NewConfigFrom(map[string]interface{}{
"hosts": GetEsHost(),
"username": os.Getenv("ES_USER"),
"password": os.Getenv("ES_PASS"),
"template.enabled": false,
})
if err != nil {
t.Fatal(err)
}
tmp, err := common.NewConfigFrom(cfg)
if err != nil {
t.Fatal(err)
}
err = config.Merge(tmp)
if err != nil {
t.Fatal(err)
}
output, err := New("libbeat", config, 0)
if err != nil {
t.Fatal(err)
}
es := output.(*elasticsearchOutput)
client := es.randomClient()
// Load version number
client.Connect(3 * time.Second)
return es, client
}
开发者ID:urso,项目名称:beats,代码行数:33,代码来源:client_integration_test.go
示例2: getRedisModuleConfig
func getRedisModuleConfig(pass string) (*common.Config, error) {
return common.NewConfigFrom(RedisModuleConfig{
Module: "redis",
Hosts: []string{LOCAL_REDIS},
Password: pass,
})
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:7,代码来源:info_test.go
示例3: TestModuleRunner
func TestModuleRunner(t *testing.T) {
pubClient, factory := newPubClientFactory()
config, err := common.NewConfigFrom(map[string]interface{}{
"module": moduleName,
"metricsets": []string{metricSetName},
})
if err != nil {
t.Fatal(err)
}
// Create a new ModuleWrapper based on the configuration.
module, err := metricbeat.NewModuleWrapper(config, mb.Registry)
if err != nil {
t.Fatal(err)
}
// Create the ModuleRunner facade.
runner := metricbeat.NewModuleRunner(factory, module)
// Start the module and have it publish to a new publisher.Client.
runner.Start()
assert.NotNil(t, <-pubClient.Channel)
// Stop the module. This blocks until all MetricSets in the Module have
// stopped and the publisher.Client is closed.
runner.Stop()
}
开发者ID:ChongFeng,项目名称:beats,代码行数:29,代码来源:runner_test.go
示例4: newConfig
func newConfig(t testing.TB, moduleConfig interface{}) *common.Config {
config, err := common.NewConfigFrom(moduleConfig)
if err != nil {
t.Fatal(err)
}
return config
}
开发者ID:ChongFeng,项目名称:beats,代码行数:7,代码来源:module_test.go
示例5: createWatchUpdater
func createWatchUpdater(monitor *Monitor) func(content []byte) {
return func(content []byte) {
defer logp.Recover("Failed applying monitor watch")
// read multiple json objects from content
dec := json.NewDecoder(bytes.NewBuffer(content))
var configs []*common.Config
for dec.More() {
var obj map[string]interface{}
err := dec.Decode(&obj)
if err != nil {
logp.Err("Failed parsing json object: %v", err)
return
}
logp.Info("load watch object: %v", obj)
cfg, err := common.NewConfigFrom(obj)
if err != nil {
logp.Err("Failed normalizing json input: %v", err)
return
}
configs = append(configs, cfg)
}
// apply read configurations
if err := monitor.Update(configs); err != nil {
logp.Err("Failed applying configuration: %v", err)
}
}
}
开发者ID:andrewkroh,项目名称:beats,代码行数:32,代码来源:manager.go
示例6: newTestLumberjackOutput
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, _ := common.NewConfigFrom(config)
output, err := plugin("", cfg, 0)
if err != nil {
t.Fatalf("init logstash output plugin failed: %v", err)
}
return output.(outputs.BulkOutputer)
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:25,代码来源:logstash_test.go
示例7: TestNamespace
func TestNamespace(t *testing.T) {
tests := []struct {
name string
}{
{"test"},
{"test.test"},
{"abc.def.test"},
}
for i, test := range tests {
t.Logf("run (%v): %v", i, test.name)
ns := NewNamespace()
err := ns.Register(test.name, newTestFilterRule)
fatalError(t, err)
cfg, _ := common.NewConfigFrom(map[string]interface{}{
test.name: nil,
})
filter, err := ns.Plugin()(*cfg)
assert.NoError(t, err)
assert.NotNil(t, filter)
}
}
开发者ID:Zhoutall,项目名称:beats,代码行数:26,代码来源:namespace_test.go
示例8: createElasticsearchConnection
func createElasticsearchConnection(flushInterval int, bulkSize int) *elasticsearchOutput {
index := fmt.Sprintf("packetbeat-int-test-%d", os.Getpid())
esPort, err := strconv.Atoi(GetEsPort())
if err != nil {
logp.Err("Invalid port. Cannot be converted to in: %s", GetEsPort())
}
config, _ := common.NewConfigFrom(map[string]interface{}{
"save_topology": true,
"hosts": []string{GetEsHost()},
"port": esPort,
"username": os.Getenv("ES_USER"),
"password": os.Getenv("ES_PASS"),
"path": "",
"index": fmt.Sprintf("%v-%%{+yyyy.MM.dd}", index),
"protocol": "http",
"flush_interval": flushInterval,
"bulk_max_size": bulkSize,
"template.enabled": false,
})
output := &elasticsearchOutput{beatName: "test"}
output.init(config, 10)
return output
}
开发者ID:andrewkroh,项目名称:beats,代码行数:27,代码来源:output_test.go
示例9: newMetricSet
// newMetricSet instantiates a new MetricSet using the given configuration.
// The ModuleFactory and MetricSetFactory are obtained from the global
// Registry.
func newMetricSet(t testing.TB, config interface{}) mb.MetricSet {
c, err := common.NewConfigFrom(config)
if err != nil {
t.Fatal(err)
}
m, err := mb.NewModules([]*common.Config{c}, mb.Registry)
if err != nil {
t.Fatal(err)
}
if !assert.Len(t, m, 1) {
t.FailNow()
}
var metricSet mb.MetricSet
for _, v := range m {
if !assert.Len(t, v, 1) {
t.FailNow()
}
metricSet = v[0]
break
}
if !assert.NotNil(t, metricSet) {
t.FailNow()
}
return metricSet
}
开发者ID:yan2jared,项目名称:beats,代码行数:31,代码来源:modules.go
示例10: newTestElasticsearchOutput
func newTestElasticsearchOutput(t *testing.T, test string) *testOutputer {
plugin := outputs.FindOutputPlugin("elasticsearch")
if plugin == nil {
t.Fatalf("No elasticsearch output plugin found")
}
index := testElasticsearchIndex(test)
connection := esConnect(t, index)
flushInterval := 0
bulkSize := 0
config, _ := common.NewConfigFrom(map[string]interface{}{
"hosts": []string{getElasticsearchHost()},
"index": index,
"flush_interval": &flushInterval,
"bulk_max_size": &bulkSize,
"username": os.Getenv("ES_USER"),
"password": os.Getenv("ES_PASS"),
})
output, err := plugin(config, 10)
if err != nil {
t.Fatalf("init elasticsearch output plugin failed: %v", err)
}
es := &testOutputer{}
es.BulkOutputer = output.(outputs.BulkOutputer)
es.esConnection = connection
return es
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:30,代码来源:logstash_integration_test.go
示例11: TestValidJSONDepthTwo
func TestValidJSONDepthTwo(t *testing.T) {
input := common.MapStr{
"msg": "{\"log\":\"{\\\"level\\\":\\\"info\\\"}\",\"stream\":\"stderr\",\"count\":3}",
"pipeline": "us1",
}
testConfig, _ = common.NewConfigFrom(map[string]interface{}{
"fields": fields,
"processArray": false,
"maxDepth": 2,
})
actual := getActualValue(t, testConfig, input)
expected := common.MapStr{
"msg": map[string]interface{}{
"log": map[string]interface{}{
"level": "info",
},
"stream": "stderr",
"count": 3,
},
"pipeline": "us1",
}
assert.Equal(t, expected.String(), actual.String())
}
开发者ID:ruflin,项目名称:beats,代码行数:28,代码来源:decode_json_fields_test.go
示例12: newRedisTestingOutput
func newRedisTestingOutput(t *testing.T, cfg map[string]interface{}) *redisOut {
params := struct {
Expire int `config:"topology_expire"`
}{15}
config, err := common.NewConfigFrom(cfg)
if err != nil {
t.Fatalf("Error reading config: %v", err)
}
plugin := outputs.FindOutputPlugin("redis")
if plugin == nil {
t.Fatalf("redis output module not registered")
}
if err := config.Unpack(¶ms); err != nil {
t.Fatalf("Failed to unpack topology_expire: %v", err)
}
out, err := plugin("libbeat", config, params.Expire)
if err != nil {
t.Fatalf("Failed to initialize redis output: %v", err)
}
return out.(*redisOut)
}
开发者ID:ChongFeng,项目名称:beats,代码行数:26,代码来源:redis_integration_test.go
示例13: TestModuleConfig
func TestModuleConfig(t *testing.T) {
tests := []struct {
in map[string]interface{}
out ModuleConfig
err string
}{
{
in: map[string]interface{}{},
out: defaultModuleConfig,
},
}
for _, test := range tests {
c, err := common.NewConfigFrom(test.in)
if err != nil {
t.Fatal(err)
}
mc := defaultModuleConfig
err = c.Unpack(&mc)
if test.err != "" {
assert.Error(t, err)
assert.Contains(t, err.Error(), test.err)
continue
}
assert.Equal(t, test.out, mc)
}
}
开发者ID:tanlintan,项目名称:pingbeat,代码行数:29,代码来源:mb_test.go
示例14: ExampleModuleRunner
// ExampleModuleRunner demonstrates how to use ModuleRunner to start and stop
// a module.
func ExampleModuleRunner() {
// A *beat.Beat is injected into a Beater when it runs and contains the
// Publisher used to publish events. This Beat pointer is created here only
// for demonstration purposes.
var b *beat.Beat
config, err := common.NewConfigFrom(map[string]interface{}{
"module": moduleName,
"metricsets": []string{metricSetName},
})
if err != nil {
return
}
// Create a new ModuleWrapper based on the configuration.
module, err := metricbeat.NewModuleWrapper(config, mb.Registry)
if err != nil {
return
}
// Create the ModuleRunner facade.
runner := metricbeat.NewModuleRunner(b.Publisher.Connect, module)
// Start the module and have it publish to a new publisher.Client.
runner.Start()
// Stop the module. This blocks until all MetricSets in the Module have
// stopped and the publisher.Client is closed.
runner.Stop()
}
开发者ID:mrkschan,项目名称:beats,代码行数:32,代码来源:example_test.go
示例15: mustNewConfigFrom
func mustNewConfigFrom(from interface{}) *common.Config {
cfg, err := common.NewConfigFrom(from)
if err != nil {
panic(err)
}
return cfg
}
开发者ID:ChongFeng,项目名称:beats,代码行数:7,代码来源:cfgfile.go
示例16: makeConfig
func makeConfig(t *testing.T, in map[string]interface{}) *common.Config {
cfg, err := common.NewConfigFrom(in)
if err != nil {
t.Fatal(err)
}
return cfg
}
开发者ID:YaSuenag,项目名称:hsbeat,代码行数:7,代码来源:kafka_integration_test.go
示例17: TestMissingFields
func TestMissingFields(t *testing.T) {
if testing.Verbose() {
logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"*"})
}
yml := []map[string]interface{}{
map[string]interface{}{
"include_fields": map[string]interface{}{
"equals": map[string]string{
"type": "process",
},
},
},
}
config := filter.FilterPluginConfig{}
for _, rule := range yml {
c := map[string]common.Config{}
for name, ruleYml := range rule {
ruleConfig, err := common.NewConfigFrom(ruleYml)
assert.Nil(t, err)
c[name] = *ruleConfig
}
config = append(config, c)
}
_, err := filter.New(config)
assert.NotNil(t, err)
}
开发者ID:McStork,项目名称:beats,代码行数:34,代码来源:filter_test.go
示例18: TestOutputLoadTemplate
// TestOutputLoadTemplate checks that the template is inserted before
// the first event is published.
func TestOutputLoadTemplate(t *testing.T) {
client := GetTestingElasticsearch()
err := client.Connect(5 * time.Second)
if err != nil {
t.Fatal(err)
}
// delete template if it exists
client.request("DELETE", "/_template/libbeat", "", nil, nil)
// Make sure template is not yet there
assert.False(t, client.CheckTemplate("libbeat"))
templatePath := "../../../packetbeat/packetbeat.template.json"
if strings.HasPrefix(client.Connection.version, "2.") {
templatePath = "../../../packetbeat/packetbeat.template-es2x.json"
}
tPath, err := filepath.Abs(templatePath)
if err != nil {
t.Fatal(err)
}
config := map[string]interface{}{
"hosts": GetEsHost(),
"template": map[string]interface{}{
"name": "libbeat",
"path": tPath,
"versions.2x.enabled": false,
},
}
cfg, err := common.NewConfigFrom(config)
if err != nil {
t.Fatal(err)
}
output, err := New("libbeat", cfg, 0)
if err != nil {
t.Fatal(err)
}
event := outputs.Data{Event: common.MapStr{
"@timestamp": common.Time(time.Now()),
"host": "test-host",
"type": "libbeat",
"message": "Test message from libbeat",
}}
err = output.PublishEvent(nil, outputs.Options{Guaranteed: true}, event)
if err != nil {
t.Fatal(err)
}
// Guaranteed publish, so the template should be there
assert.True(t, client.CheckTemplate("libbeat"))
}
开发者ID:urso,项目名称:beats,代码行数:61,代码来源:client_integration_test.go
示例19: NewTestModule
func NewTestModule(t testing.TB, config interface{}) *TestModule {
c, err := common.NewConfigFrom(config)
if err != nil {
t.Fatal(err)
}
return &TestModule{RawConfig: c}
}
开发者ID:ruflin,项目名称:beats,代码行数:8,代码来源:modules.go
示例20: TestWhenProcessor
func TestWhenProcessor(t *testing.T) {
type config map[string]interface{}
tests := []struct {
title string
filter config
events []common.MapStr
expected int
}{
{
"condition_matches",
config{"when.equals.i": 10},
[]common.MapStr{{"i": 10}},
1,
},
{
"condition_fails",
config{"when.equals.i": 11},
[]common.MapStr{{"i": 10}},
0,
},
{
"no_condition",
config{},
[]common.MapStr{{"i": 10}},
1,
},
}
for i, test := range tests {
t.Logf("run test (%v): %v", i, test.title)
config, err := common.NewConfigFrom(test.filter)
if err != nil {
t.Error(err)
continue
}
cf := &countFilter{}
filter, err := NewConditional(func(_ common.Config) (Processor, error) {
return cf, nil
})(*config)
if err != nil {
t.Error(err)
continue
}
for _, event := range test.events {
_, err := filter.Run(event)
if err != nil {
t.Error(err)
}
}
assert.Equal(t, test.expected, cf.N)
}
}
开发者ID:ChongFeng,项目名称:beats,代码行数:57,代码来源:condition_test.go
注:本文中的github.com/elastic/beats/libbeat/common.NewConfigFrom函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论