forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
40 lines (33 loc) · 944 Bytes
/
factory.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 prospector
import (
"github.com/elastic/beats/filebeat/registrar"
"github.com/elastic/beats/libbeat/cfgfile"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
type Factory struct {
outlet Outlet
registrar *registrar.Registrar
beatDone chan struct{}
}
func NewFactory(outlet Outlet, registrar *registrar.Registrar, beatDone chan struct{}) *Factory {
return &Factory{
outlet: outlet,
registrar: registrar,
beatDone: beatDone,
}
}
func (r *Factory) Create(c *common.Config) (cfgfile.Runner, error) {
p, err := NewProspector(c, r.outlet, r.beatDone)
if err != nil {
logp.Err("Error creating prospector: %s", err)
return nil, err
}
err = p.LoadStates(r.registrar.GetStates())
if err != nil {
logp.Err("Error loading states for prospector %v: %v", p.ID(), err)
// In case of error with loading state, prospector is still returne
return p, err
}
return p, nil
}