1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
output.go 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
package test
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/elastic/beats/libbeat/cmd/instance"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/testing"
)
func GenTestOutputCmd(name, beatVersion string) *cobra.Command {
return &cobra.Command{
Use: "output",
Short: "Test " + name + " can connect to the output by using the current settings",
Run: func(cmd *cobra.Command, args []string) {
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)
}
output, err := outputs.Load(b.Info, nil, b.Config.Output.Name(), b.Config.Output.Config())
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing output: %s\n", err)
os.Exit(1)
}
for _, client := range output.Clients {
tClient, ok := client.(testing.Testable)
if !ok {
fmt.Printf("%s output doesn't support testing\n", b.Config.Output.Name())
os.Exit(1)
}
// Perform test:
tClient.Test(testing.NewConsoleDriver(os.Stdout))
}
},
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.2.2

搜索帮助