1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
modules.go 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
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)
}
})
}
},
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.1.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385