forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
connector.go
48 lines (41 loc) · 1.25 KB
/
connector.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
package module
import (
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/processors"
)
// Connector configures and establishes a beat.Client for publishing events
// to the publisher pipeline.
type Connector struct {
pipeline beat.Pipeline
processors *processors.Processors
eventMeta common.EventMetadata
dynamicFields *common.MapStrPointer
}
type connectorConfig struct {
Processors processors.PluginConfig `config:"processors"`
common.EventMetadata `config:",inline"` // Fields and tags to add to events.
}
func NewConnector(pipeline beat.Pipeline, c *common.Config, dynFields *common.MapStrPointer) (*Connector, error) {
config := connectorConfig{}
if err := c.Unpack(&config); err != nil {
return nil, err
}
processors, err := processors.New(config.Processors)
if err != nil {
return nil, err
}
return &Connector{
pipeline: pipeline,
processors: processors,
eventMeta: config.EventMetadata,
dynamicFields: dynFields,
}, nil
}
func (c *Connector) Connect() (beat.Client, error) {
return c.pipeline.ConnectWith(beat.ClientConfig{
EventMetadata: c.eventMeta,
Processor: c.processors,
DynamicFields: c.dynamicFields,
})
}