Beispiel #1
0
// Test OutputWorker by calling onStop() and onMessage() with various inputs.
func TestOutputWorker(t *testing.T) {
	outputer := &testOutputer{data: make(chan outputs.Data, 10)}
	ow := newOutputWorker(
		common.NewConfig(),
		outputer,
		newWorkerSignal(),
		1, 0)

	ow.onStop() // Noop

	var testCases = []message{
		testMessage(newTestSignaler(), outputs.Data{}),
		testMessage(newTestSignaler(), testEvent()),
		testBulkMessage(newTestSignaler(), []outputs.Data{testEvent()}),
	}

	for _, m := range testCases {
		sig := m.context.Signal.(*testSignaler)
		ow.onMessage(m)
		assert.True(t, sig.wait())

		if m.datum.Event != nil {
			assert.Equal(t, m.datum, <-outputer.data)
		} else {
			for _, e := range m.data {
				assert.Equal(t, e, <-outputer.data)
			}
		}
	}
}
Beispiel #2
0
func (b *Beat) launch(bt Creator) error {
	err := b.handleFlags()
	if err != nil {
		return err
	}

	svc.BeforeRun()
	defer svc.Cleanup()

	if err := b.configure(); err != nil {
		return err
	}

	// load the beats config section
	var sub *common.Config
	configName := strings.ToLower(b.Name)
	if b.RawConfig.HasField(configName) {
		sub, err = b.RawConfig.Child(configName, -1)
		if err != nil {
			return err
		}
	} else {
		sub = common.NewConfig()
	}

	logp.Info("Setup Beat: %s; Version: %s", b.Name, b.Version)
	processors, err := processors.New(b.Config.Processors)
	if err != nil {
		return fmt.Errorf("error initializing processors: %v", err)
	}

	debugf("Initializing output plugins")
	publisher, err := publisher.New(b.Name, b.Config.Output, b.Config.Shipper, processors)
	if err != nil {
		return fmt.Errorf("error initializing publisher: %v", err)
	}

	// TODO: some beats race on shutdown with publisher.Stop -> do not call Stop yet,
	//       but refine publisher to disconnect clients on stop automatically
	// defer publisher.Stop()

	b.Publisher = publisher
	beater, err := bt(b, sub)
	if err != nil {
		return err
	}

	// If -configtest was specified, exit now prior to run.
	if cfgfile.IsTestConfig() {
		fmt.Println("Config OK")
		return GracefulExit
	}

	svc.HandleSignals(beater.Stop)

	logp.Info("%s start running.", b.Name)
	defer logp.Info("%s stopped.", b.Name)

	return beater.Run(b)
}
Beispiel #3
0
func BenchmarkIcmpProcessICMPv4(b *testing.B) {
	if testing.Verbose() {
		logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"icmp", "icmpdetailed"})
	}

	results := &publish.ChanTransactions{make(chan common.MapStr, 10)}
	icmp, err := New(true, results, common.NewConfig())
	if err != nil {
		b.Error("Failed to create ICMP processor")
		return
	}

	icmpRequestData := createICMPv4Layer(b, "08"+"00"+"0000"+"ffff"+"0001")
	packetRequestData := new(protos.Packet)

	icmpResponseData := createICMPv4Layer(b, "00"+"00"+"0000"+"ffff"+"0001")
	packetResponseData := new(protos.Packet)

	b.ResetTimer()

	for n := 0; n < b.N; n++ {
		icmp.ProcessICMPv4(nil, icmpRequestData, packetRequestData)
		icmp.ProcessICMPv4(nil, icmpResponseData, packetResponseData)

		client := icmp.results.(*publish.ChanTransactions)
		<-client.Channel
	}
}
Beispiel #4
0
func httpModForTests() *httpPlugin {
	results := &publish.ChanTransactions{Channel: make(chan common.MapStr, 10)}
	http, err := New(false, results, common.NewConfig())
	if err != nil {
		panic(err)
	}
	return http.(*httpPlugin)
}
Beispiel #5
0
func TestProspectorDefaultConfigs(t *testing.T) {

	prospector, err := NewProspector(common.NewConfig(), *input.NewStates(), nil)
	assert.NoError(t, err)

	// Default values expected
	assert.Equal(t, DefaultIgnoreOlder, prospector.config.IgnoreOlder)
	assert.Equal(t, DefaultScanFrequency, prospector.config.ScanFrequency)
	assert.Equal(t, config.DefaultHarvesterBufferSize, prospector.config.Harvester.BufferSize)
	assert.Equal(t, config.DefaultTailFiles, prospector.config.Harvester.TailFiles)
	assert.Equal(t, config.DefaultBackoff, prospector.config.Harvester.BackoffDuration)
	assert.Equal(t, config.DefaultBackoffFactor, prospector.config.Harvester.BackoffFactor)
	assert.Equal(t, config.DefaultMaxBackoff, prospector.config.Harvester.MaxBackoffDuration)
	assert.Equal(t, config.DefaultForceCloseFiles, prospector.config.Harvester.ForceCloseFiles)
	assert.Equal(t, config.DefaultMaxBytes, prospector.config.Harvester.MaxBytes)
}