forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautodiscover.go
46 lines (38 loc) · 1.46 KB
/
autodiscover.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
package beater
import (
"errors"
"github.com/elastic/beats/libbeat/cfgfile"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/bus"
)
// AutodiscoverAdapter for Metricbeat modules
type AutodiscoverAdapter struct {
factory cfgfile.RunnerFactory
}
// NewAutodiscoverAdapter builds and returns an autodiscover adapter for Metricbeat modules
func NewAutodiscoverAdapter(factory cfgfile.RunnerFactory) *AutodiscoverAdapter {
return &AutodiscoverAdapter{
factory: factory,
}
}
// CreateConfig generates a valid list of configs from the given event, the received event will have all keys defined by `StartFilter`
func (m *AutodiscoverAdapter) CreateConfig(e bus.Event) ([]*common.Config, error) {
config, ok := e["config"].([]*common.Config)
if !ok {
return nil, errors.New("Got a wrong value in event `config` key")
}
return config, nil
}
// CheckConfig tests given config to check if it will work or not, returns errors in case it won't work
func (m *AutodiscoverAdapter) CheckConfig(c *common.Config) error {
// TODO implment config check for all modules
return nil
}
// Create a module or prospector from the given config
func (m *AutodiscoverAdapter) Create(c *common.Config, meta *common.MapStrPointer) (cfgfile.Runner, error) {
return m.factory.Create(c, meta)
}
// EventFilter returns the bus filter to retrieve runner start/stop triggering events
func (m *AutodiscoverAdapter) EventFilter() []string {
return []string{"config"}
}