-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
root.go
66 lines (57 loc) · 2.11 KB
/
root.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
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package cmd
import (
"fmt"
"os"
fbcmd "github.com/elastic/beats/v7/filebeat/cmd"
cmd "github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/processors"
"github.com/elastic/beats/v7/libbeat/publisher/processing"
"github.com/elastic/beats/v7/x-pack/libbeat/management"
"github.com/elastic/elastic-agent-libs/mapstr"
// Register the includes.
_ "github.com/elastic/beats/v7/x-pack/filebeat/include"
inputs "github.com/elastic/beats/v7/x-pack/filebeat/input/default-inputs"
_ "github.com/elastic/beats/v7/x-pack/libbeat/include"
)
// Name is the name of the beat
const Name = fbcmd.Name
// Filebeat build the beat root command for executing filebeat and it's subcommands.
func Filebeat() *cmd.BeatsRootCmd {
management.ConfigTransform.SetTransform(filebeatCfg)
settings := fbcmd.FilebeatSettings()
globalProcs, err := processors.NewPluginConfigFromList(defaultProcessors())
if err != nil { // these are hard-coded, shouldn't fail
panic(fmt.Errorf("error creating global processors: %w", err))
}
settings.Processing = processing.MakeDefaultSupport(true, globalProcs, processing.WithECS, processing.WithHost, processing.WithAgentMeta())
settings.ElasticLicensed = true
command := fbcmd.Filebeat(inputs.Init, settings)
return command
}
func defaultProcessors() []mapstr.M {
// processors:
// - add_host_metadata:
// when.not.contains.tags: forwarded
// - add_cloud_metadata: ~
// - add_docker_metadata: ~
// - add_kubernetes_metadata: ~
// This gets called early enough that the CLI handling isn't properly initialized yet,
// so use an environment variable.
shipperEnv := os.Getenv("SHIPPER_MODE")
if shipperEnv == "True" {
return []mapstr.M{}
}
return []mapstr.M{
{
"add_host_metadata": mapstr.M{
"when.not.contains.tags": "forwarded",
},
},
{"add_cloud_metadata": nil},
{"add_docker_metadata": nil},
{"add_kubernetes_metadata": nil},
}
}