forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prospector.go
59 lines (47 loc) · 1.62 KB
/
prospector.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
52
53
54
55
56
57
58
59
package docker
import (
"fmt"
"path"
"github.com/elastic/beats/filebeat/channel"
"github.com/elastic/beats/filebeat/prospector"
"github.com/elastic/beats/filebeat/prospector/log"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/pkg/errors"
)
func init() {
err := prospector.Register("docker", NewProspector)
if err != nil {
panic(err)
}
}
// NewProspector creates a new docker prospector
func NewProspector(cfg *common.Config, outletFactory channel.Factory, context prospector.Context) (prospector.Prospectorer, error) {
cfgwarn.Experimental("Docker prospector is enabled.")
config := defaultConfig
if err := cfg.Unpack(&config); err != nil {
return nil, errors.Wrap(err, "reading docker prospector config")
}
// Wrap log prospector with custom docker settings
if len(config.Containers.IDs) == 0 {
return nil, errors.New("Docker prospector requires at least one entry under 'containers.ids'")
}
for idx, containerID := range config.Containers.IDs {
cfg.SetString("paths", idx, path.Join(config.Containers.Path, containerID, "*.log"))
}
if err := checkStream(config.Containers.Stream); err != nil {
return nil, err
}
if err := cfg.SetString("docker-json", -1, config.Containers.Stream); err != nil {
return nil, errors.Wrap(err, "update prospector config")
}
return log.NewProspector(cfg, outletFactory, context)
}
func checkStream(val string) error {
for _, s := range []string{"all", "stdout", "stderr"} {
if s == val {
return nil
}
}
return fmt.Errorf("Invalid value for containers.stream: %s, supported values are: all, stdout, stderr", val)
}