-
Notifications
You must be signed in to change notification settings - Fork 0
/
logstash.go
76 lines (62 loc) · 1.64 KB
/
logstash.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
73
74
75
76
package logstash
import (
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/outputs/transport"
)
const (
minWindowSize int = 1
defaultStartMaxWindowSize int = 10
)
var debugf = logp.MakeDebug("logstash")
func init() {
outputs.RegisterType("logstash", makeLogstash)
}
func makeLogstash(
beat beat.Info,
stats *outputs.Stats,
cfg *common.Config,
) (outputs.Group, error) {
if !cfg.HasField("index") {
cfg.SetString("index", -1, beat.Beat)
}
config := newConfig()
if err := cfg.Unpack(config); err != nil {
return outputs.Fail(err)
}
hosts, err := outputs.ReadHostList(cfg)
if err != nil {
return outputs.Fail(err)
}
tls, err := outputs.LoadTLSConfig(config.TLS)
if err != nil {
return outputs.Fail(err)
}
transp := &transport.Config{
Timeout: config.Timeout,
Proxy: &config.Proxy,
TLS: tls,
Stats: stats,
}
clients := make([]outputs.NetworkClient, len(hosts))
for i, host := range hosts {
var client outputs.NetworkClient
conn, err := transport.NewClient(transp, "tcp", host, config.Port)
if err != nil {
return outputs.Fail(err)
}
if config.Pipelining > 0 {
client, err = newAsyncClient(beat, conn, stats, config)
} else {
client, err = newSyncClient(beat, conn, stats, config)
}
if err != nil {
return outputs.Fail(err)
}
client = outputs.WithBackoff(client, config.Backoff.Init, config.Backoff.Max)
clients[i] = client
}
return outputs.SuccessNet(config.LoadBalance, config.BulkMaxSize, config.MaxRetries, clients)
}