Пример #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
func NewConfig(in []byte, opts ...ucfg.Option) (*ucfg.Config, error) {
	var m map[string]interface{}
	if err := json.Unmarshal(in, &m); err != nil {
		return nil, err
	}
	return ucfg.NewFrom(m, opts...)
}
Пример #3
0
func createElasticsearchConnection(flushInterval int, bulkSize int) elasticsearchOutput {
	index := fmt.Sprintf("packetbeat-unittest-%d", os.Getpid())

	esPort, err := strconv.Atoi(GetEsPort())

	if err != nil {
		logp.Err("Invalid port. Cannot be converted to in: %s", GetEsPort())
	}

	config, _ := ucfg.NewFrom(map[string]interface{}{
		"save_topology":  true,
		"hosts":          []string{GetEsHost()},
		"port":           esPort,
		"username":       os.Getenv("ES_USER"),
		"password":       os.Getenv("ES_PASS"),
		"path":           "",
		"index":          index,
		"protocol":       "http",
		"flush_interval": flushInterval,
		"bulk_max_size":  bulkSize,
	})

	var output elasticsearchOutput
	output.init(config, 10)
	return output
}
Пример #4
0
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, _ := ucfg.NewFrom(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
}
Пример #5
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)
}
Пример #6
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
}
Пример #7
0
func newDns(verbose bool) *Dns {
	if verbose {
		logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"dns"})
	} else {
		logp.LogInit(logp.LOG_EMERG, "", false, true, []string{"dns"})
	}

	results := &publish.ChanTransactions{make(chan common.MapStr, 100)}
	cfg, _ := ucfg.NewFrom(map[string]interface{}{
		"ports":               []int{ServerPort},
		"include_authorities": true,
		"include_additionals": true,
		"send_request":        true,
		"send_response":       true,
	})
	dns, err := New(false, results, cfg)
	if err != nil {
		panic(err)
	}

	return dns.(*Dns)
}
Пример #8
0
func NewConfigFrom(from interface{}) (*Config, error) {
	c, err := ucfg.NewFrom(from, ucfg.PathSep("."))
	return fromConfig(c), err
}