forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 2
/
forwarder.go
40 lines (32 loc) · 1.02 KB
/
forwarder.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
package harvester
import (
"errors"
"github.com/elastic/beats/filebeat/util"
"github.com/elastic/beats/libbeat/logp"
)
// Outlet interface is used for forwarding events
type Outlet interface {
OnEvent(data *util.Data) bool
}
// Forwarder contains shared options between all harvesters needed to forward events
type Forwarder struct {
Outlet Outlet
}
// ForwarderConfig contains all config options shared by all harvesters
type ForwarderConfig struct {
Type string `config:"type"`
}
// NewForwarder creates a new forwarder instances and initialises processors if configured
func NewForwarder(outlet Outlet) *Forwarder {
return &Forwarder{Outlet: outlet}
}
// Send updates the prospector state and sends the event to the spooler
// All state updates done by the prospector itself are synchronous to make sure no states are overwritten
func (f *Forwarder) Send(data *util.Data) error {
ok := f.Outlet.OnEvent(data)
if !ok {
logp.Info("Prospector outlet closed")
return errors.New("prospector outlet closed")
}
return nil
}