forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
49 lines (41 loc) · 1.19 KB
/
output.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
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))
}
},
}
}