-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathroot.go
72 lines (62 loc) · 2.38 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
67
68
69
70
71
72
// 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"
"github.com/spf13/cobra"
"github.com/elastic/beats/v7/libbeat/cmd"
"github.com/elastic/beats/v7/libbeat/ecs"
"github.com/elastic/beats/v7/libbeat/processors"
"github.com/elastic/beats/v7/libbeat/publisher/processing"
"github.com/elastic/beats/v7/metricbeat/beater"
mbcmd "github.com/elastic/beats/v7/metricbeat/cmd"
"github.com/elastic/beats/v7/metricbeat/cmd/test"
"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/libbeat/include"
_ "github.com/elastic/beats/v7/x-pack/metricbeat/include"
// Import OSS modules.
_ "github.com/elastic/beats/v7/metricbeat/include"
_ "github.com/elastic/beats/v7/metricbeat/include/fields"
)
const (
// Name of the beat
Name = "metricbeat"
)
// withECSVersion is a modifier that adds ecs.version to events.
var withECSVersion = processing.WithFields(mapstr.M{
"ecs": mapstr.M{
"version": ecs.Version,
},
})
func Initialize() *cmd.BeatsRootCmd {
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 := mbcmd.MetricbeatSettings("")
settings.ElasticLicensed = true
settings.Processing = processing.MakeDefaultSupport(true, globalProcs, withECSVersion, processing.WithHost, processing.WithAgentMeta())
rootCmd := cmd.GenRootCmdWithSettings(beater.DefaultCreator(), settings)
rootCmd.AddCommand(cmd.GenModulesCmd(Name, "", mbcmd.BuildModulesManager))
rootCmd.TestCmd.AddCommand(test.GenTestModulesCmd(Name, "", beater.DefaultTestModulesCreator()))
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
management.ConfigTransform.SetTransform(metricbeatCfg)
}
return rootCmd
}
func defaultProcessors() []mapstr.M {
// processors:
// - add_host_metadata: ~
// - add_cloud_metadata: ~
// - add_docker_metadata: ~
// - add_kubernetes_metadata: ~
return []mapstr.M{
{"add_host_metadata": nil},
{"add_cloud_metadata": nil},
{"add_docker_metadata": nil},
{"add_kubernetes_metadata": nil},
}
}