forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
70 lines (57 loc) · 2.13 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"fmt"
"os"
"github.com/docker/go-plugins-helpers/sdk"
"github.com/elastic/beats/libbeat/common"
logpcfg "github.com/elastic/beats/libbeat/logp/configure"
_ "github.com/elastic/beats/libbeat/outputs/console"
_ "github.com/elastic/beats/libbeat/outputs/elasticsearch"
_ "github.com/elastic/beats/libbeat/outputs/fileout"
_ "github.com/elastic/beats/libbeat/outputs/kafka"
_ "github.com/elastic/beats/libbeat/outputs/logstash"
_ "github.com/elastic/beats/libbeat/outputs/redis"
_ "github.com/elastic/beats/libbeat/publisher/queue/memqueue"
_ "github.com/elastic/beats/libbeat/publisher/queue/spool"
"github.com/elastic/beats/libbeat/service"
"github.com/elastic/beats/x-pack/dockerlogbeat/pipelinemanager"
)
// genNewMonitoringConfig is a hacked-in function to enable a debug stderr logger
func genNewMonitoringConfig() (*common.Config, error) {
cfgObject := make(map[string]string)
cfgObject["level"] = "debug"
cfgObject["to_stderr"] = "true"
cfg, err := common.NewConfigFrom(cfgObject)
if err != nil {
return nil, err
}
return cfg, nil
}
func fatal(format string, vs ...interface{}) {
fmt.Fprintf(os.Stderr, format, vs...)
os.Exit(1)
}
func main() {
service.BeforeRun()
defer service.Cleanup()
logcfg, err := genNewMonitoringConfig()
if err != nil {
fatal("error starting config: %s", err)
}
err = logpcfg.Logging("elastic-logging-driver", logcfg)
if err != nil {
fatal("error starting log handler: %s", err)
}
pipelines := pipelinemanager.NewPipelineManager(logcfg)
sdkHandler := sdk.NewHandler(`{"Implements": ["LoggingDriver"]}`)
// Create handlers for startup and shutdown of the log driver
sdkHandler.HandleFunc("/LogDriver.StartLogging", startLoggingHandler(pipelines))
sdkHandler.HandleFunc("/LogDriver.StopLogging", stopLoggingHandler(pipelines))
err = sdkHandler.ServeUnix("beatSocket", 0)
if err != nil {
fatal("Error in socket handler: %s", err)
}
}