qfilter_grok

package module
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

README

filter-grok

Filter to apply GROK statements against a message.

Hello World

As a standalone program like this:

func main() {
	qChan := qtypes.NewQChan()
	qChan.Broadcast()
	cfgMap := map[string]string{
		"filter.test.pattern": "%{INT:number}",
		"filter.test.inputs": "test",
	}

	cfg := config.NewConfig(
		[]config.Provider{
			config.NewStatic(cfgMap),
		},
	)
	p, err := qframe_filter_grok.New(qChan, *cfg, "test")
	if err != nil {
		log.Printf("[EE] Failed to create filter: %v", err)
		return
	}
	go p.Run()
	time.Sleep(2*time.Second)
	bg := qChan.Data.Join()
	qm := qtypes.NewQMsg("test", "test")
	qm.Msg = "1"
	log.Println("Send message")
	qChan.Data.Send(qm)
	for {
		qm = bg.Recv().(qtypes.QMsg)
		if qm.Source == "test" {
			continue
		}
		fmt.Printf("#### Received result from grok (pattern:%s) filter for input: %s\n", p.GetPattern(), qm.Msg)
		for k, v := range qm.KV {
			fmt.Printf("%+15s: %s\n", k, v)
		}
		break

	}
}

The plugin produces the following outcome:

$ go run main.go
2017/04/14 07:28:16 [II] Dispatch broadcast for Data and Tick
2017/04/14 07:28:16 [II] Start grok filter 'test' v0.0.0
2017/04/14 07:28:18 Send message
#### Received result from grok (pattern:%{INT:number}) filter for input: 1
         number: 1

Benchmark

$ go test -bench=Grok  -benchtime=5s
BenchmarkGrok-4   	  200000	     55903 ns/op
PASS
ok  	github.com/qframe/filter-grok	12.040s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	*qtypes_plugin.Plugin
	// contains filtered or unexported fields
}

func New

func New(qChan qtypes_qchannel.QChan, cfg *config.Config, name string) (p Plugin, err error)

New creates a new instance of the Plugin.

func (*Plugin) GetOverwriteKeys

func (p *Plugin) GetOverwriteKeys() []string

func (*Plugin) GetPattern

func (p *Plugin) GetPattern() string

GetPattern returns the pattern used.

func (*Plugin) InitGrok

func (p *Plugin) InitGrok()

InitGrok() kicks of grok and adds patterns to the grok-instance.

func (*Plugin) Lock added in v0.1.13

func (p *Plugin) Lock()

Lock locks the plugins' mutex.

func (*Plugin) Match

func (p *Plugin) Match(str string) (map[string]string, bool)

Match matches the pattern against a string and returns the values extracted.

func (*Plugin) Run

func (p *Plugin) Run()

Run fetches everything from the Data channel and flushes it to stdout.

func (*Plugin) Unlock added in v0.1.13

func (p *Plugin) Unlock()

Unlock unlocks the plugins' mutex.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL