forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.go
73 lines (56 loc) · 1.46 KB
/
filters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package filters
import (
"fmt"
"github.com/elastic/beats/libbeat/common"
)
// The FilterPlugin interface needs to be implemented
// by all the filtering plugins.
type FilterPlugin interface {
// New creates a new FilterPlugin instance with the
// given name and configuration.
New(name string, config map[string]interface{}) (FilterPlugin, error)
// Filter executes the filter.
Filter(event common.MapStr) (common.MapStr, error)
// String returns the name of the filter.
String() string
// Type returns the type of the filter.
Type() Filter
}
type Filter int
const (
NopFilter Filter = iota
SampleFilter
)
var FilterPluginNames = []string{
"nop",
"sample",
}
func (filter Filter) String() string {
if int(filter) < 0 || int(filter) >= len(FilterPluginNames) {
return "impossible"
}
return FilterPluginNames[filter]
}
func FilterFromName(name string) (Filter, error) {
for i, pluginname := range FilterPluginNames {
if name == pluginname {
return Filter(i), nil
}
}
return -1, fmt.Errorf("No filter named %s", name)
}
// Contains a list of the available filter plugins.
type FiltersList struct {
filters map[Filter]FilterPlugin
}
var Filters FiltersList
func (filters FiltersList) Register(filter Filter, plugin FilterPlugin) {
filters.filters[filter] = plugin
}
func (filters FiltersList) Get(filter Filter) FilterPlugin {
return filters.filters[filter]
}
func init() {
Filters = FiltersList{}
Filters.filters = make(map[Filter]FilterPlugin)
}