forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules.go
68 lines (58 loc) · 1.57 KB
/
modules.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
package test
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/elastic/beats/libbeat/cmd/instance"
"github.com/elastic/beats/libbeat/testing"
"github.com/elastic/beats/metricbeat/beater"
)
func GenTestModulesCmd(name, beatVersion string) *cobra.Command {
return &cobra.Command{
Use: "modules [module] [metricset]",
Short: "Test modules settings",
Run: func(cmd *cobra.Command, args []string) {
var filter_module, filter_metricset string
if len(args) > 0 {
filter_module = args[0]
}
if len(args) > 1 {
filter_metricset = args[1]
}
b, err := instance.NewBeat(name, "", beatVersion)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
}
err = b.Init()
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
}
mb, err := beater.New(&b.Beat, b.Beat.BeatConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing metricbeat: %s\n", err)
os.Exit(1)
}
modules, err := mb.(*beater.Metricbeat).Modules()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting metricbeat modules: %s\n", err)
os.Exit(1)
}
driver := testing.NewConsoleDriver(os.Stdout)
for _, module := range modules {
if filter_module != "" && module.Name() != filter_module {
continue
}
driver.Run(module.Name(), func(driver testing.Driver) {
for _, set := range module.MetricSets() {
if filter_metricset != "" && set.Name() != filter_metricset {
continue
}
set.Test(driver)
}
})
}
},
}
}