-
Notifications
You must be signed in to change notification settings - Fork 0
/
autodiscover.go
51 lines (42 loc) · 1.63 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
47
48
49
50
51
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)
}
// StartFilter returns the bus filter to retrieve runner start triggering events
func (m *AutodiscoverAdapter) StartFilter() []string {
return []string{"start", "config"}
}
// StopFilter returns the bus filter to retrieve runner stop triggering events
func (m *AutodiscoverAdapter) StopFilter() []string {
return []string{"stop", "config"}
}