forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transformer.go
47 lines (41 loc) · 1.01 KB
/
transformer.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
package kibana
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/go-ucfg/yaml"
)
type transformer struct {
entries []kibanaEntry
}
type kibanaEntry struct {
Kibana struct {
SourceFilters []string `config:"source_filters"`
} `config:"kibana"`
}
func newTransformer(entries []kibanaEntry) *transformer {
return &transformer{entries: entries}
}
func (t *transformer) transform() common.MapStr {
transformed := common.MapStr{}
var srcFilters []common.MapStr
for _, entry := range t.entries {
for _, sourceFilter := range entry.Kibana.SourceFilters {
srcFilters = append(srcFilters, common.MapStr{"value": sourceFilter})
}
}
if len(srcFilters) > 0 {
transformed["sourceFilters"] = srcFilters
}
return transformed
}
func loadKibanaEntriesFromYaml(yamlFile string) ([]kibanaEntry, error) {
entries := []kibanaEntry{}
cfg, err := yaml.NewConfigWithFile(yamlFile)
if err != nil {
return nil, err
}
err = cfg.Unpack(&entries)
if err != nil {
return nil, err
}
return entries, nil
}