本文整理匯總了Golang中github.com/elastic/beats/libbeat/common.NewConfigFrom函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewConfigFrom函數的具體用法?Golang NewConfigFrom怎麽用?Golang NewConfigFrom使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewConfigFrom函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例2: getRedisModuleConfig
func getRedisModuleConfig(pass string) (*common.Config, error) {
return common.NewConfigFrom(RedisModuleConfig{
Module: "redis",
Hosts: []string{LOCAL_REDIS},
Password: pass,
})
}
示例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()
}
示例4: newConfig
func newConfig(t testing.TB, moduleConfig interface{}) *common.Config {
config, err := common.NewConfigFrom(moduleConfig)
if err != nil {
t.Fatal(err)
}
return config
}
示例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)
}
}
}
示例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)
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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())
}
示例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)
}
示例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)
}
}
示例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()
}
示例15: mustNewConfigFrom
func mustNewConfigFrom(from interface{}) *common.Config {
cfg, err := common.NewConfigFrom(from)
if err != nil {
panic(err)
}
return cfg
}