Пример #1
0
func (mb *Metricbeat) Config(b *beat.Beat) error {

	mb.MbConfig = &MetricbeatConfig{}
	err := cfgfile.Read(mb.MbConfig, "")
	if err != nil {
		fmt.Println(err)
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	mb.ModulesConfig = &RawModulesConfig{}
	err = cfgfile.Read(mb.ModulesConfig, "")
	if err != nil {
		fmt.Println(err)
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	mb.MetricsConfig = &RawMetricsConfig{}
	err = cfgfile.Read(mb.MetricsConfig, "")
	if err != nil {
		fmt.Println(err)
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	logp.Info("Setup base and raw configuration for Modules and Metrics")
	// Apply the base configuration to each module and metric
	for moduleName, module := range helper.Registry {
		// Check if config for module exist. Only configured modules are loaded
		if _, ok := mb.MbConfig.Metricbeat.Modules[moduleName]; !ok {
			continue
		}
		module.BaseConfig = mb.MbConfig.getModuleConfig(moduleName)
		module.RawConfig = mb.ModulesConfig.Metricbeat.Modules[moduleName]
		module.Enabled = true

		for metricSetName, metricSet := range module.MetricSets {
			// Check if config for metricset exist. Only configured metricset are loaded
			if _, ok := mb.MbConfig.getModuleConfig(moduleName).MetricSets[metricSetName]; !ok {
				continue
			}
			metricSet.BaseConfig = mb.MbConfig.getModuleConfig(moduleName).MetricSets[metricSetName]
			metricSet.RawConfig = mb.MetricsConfig.Metricbeat.Modules[moduleName].MetricSets[metricSetName]
			metricSet.Enabled = true
		}
	}

	return nil
}
Пример #2
0
func (fs *FileSizeBeat) Config(b *beat.Beat) error {
	err := cfgfile.Read(&fs.config, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	if fs.config.Input.Period != nil {
		fs.period = time.Duration(*fs.config.Input.Period) * time.Second
	} else {
		fs.period = 10 * time.Second
	}
	logp.Debug("filesizebeat", "Period %v\n", fs.period)

	if fs.config.Input.Paths != nil {
		//fs.paths = make([]Path, len(*fs.config.Input.Paths))
		for _, path := range *fs.config.Input.Paths {
			err := fs.AddPath(path)
			if err != nil {
				logp.Critical("Error: %v", err)
				os.Exit(1)
			}
		}
		logp.Debug("filesizebeat", "Paths : %v\n", fs.paths)
	} else {
		logp.Critical("Error: no paths specified, cannot continue!")
		os.Exit(1)
	}
	return nil
}
Пример #3
0
func (bt *Govarbeat) Config(b *beat.Beat) error {

	cfg := &config.GovarbeatConfig{}
	err := cfgfile.Read(&cfg, "")
	if err != nil {
		return fmt.Errorf("Error reading config file: %v", err)
	}

	for name, cfg := range cfg.Remotes {
		defaultDuration := 1 * time.Second
		d := defaultDuration
		if cfg.Period != "" {
			d, err = time.ParseDuration(cfg.Period)
			if err != nil {
				return err
			}
		}

		bt.workers = append(bt.workers, &worker{
			done:   bt.done,
			host:   cfg.Host,
			name:   name,
			period: d,
		})
	}

	if len(bt.workers) == 0 {
		return fmt.Errorf("No workers configured")
	}

	return nil
}
Пример #4
0
func TestReadConfig(t *testing.T) {
	absPath, err := filepath.Abs("../tests/files/")

	assert.NotNil(t, absPath)
	assert.Nil(t, err)

	config := &ConfigSettings{}

	err = cfgfile.Read(config, absPath+"/config.yml")
	assert.Nil(t, err)

	execs := config.Execbeat.Execs
	assert.Equal(t, 2, len(execs))

	assert.Equal(t, "echo1", execs[0].Command)
	assert.Equal(t, "Execbeat", execs[0].Args)
	assert.Equal(t, "@every 1m", execs[0].Cron)
	assert.Equal(t, 2, len(execs[0].Fields))
	assert.Equal(t, "exec", execs[0].DocumentType)

	assert.Equal(t, "echo2", execs[1].Command)
	assert.Equal(t, "Hello World", execs[1].Args)
	assert.Equal(t, "@every 2m", execs[1].Cron)
	assert.Equal(t, 0, len(execs[1].Fields))
	assert.Equal(t, "", execs[1].DocumentType)
}
Пример #5
0
// Loads the beat specific config and overwrites params based on cmd line
func (pb *Packetbeat) Config(b *beat.Beat) error {

	// Read beat implementation config as needed for setup
	err := cfgfile.Read(&pb.PbConfig, "")

	// CLI flags over-riding config
	if *pb.CmdLineArgs.TopSpeed {
		pb.PbConfig.Interfaces.TopSpeed = true
	}

	if len(*pb.CmdLineArgs.File) > 0 {
		pb.PbConfig.Interfaces.File = *pb.CmdLineArgs.File
	}

	pb.PbConfig.Interfaces.Loop = *pb.CmdLineArgs.Loop
	pb.PbConfig.Interfaces.OneAtATime = *pb.CmdLineArgs.OneAtAtime

	if len(*pb.CmdLineArgs.Dumpfile) > 0 {
		pb.PbConfig.Interfaces.Dumpfile = *pb.CmdLineArgs.Dumpfile
	}

	// assign global singleton as it is used in protocols
	// TODO: Refactor
	config.ConfigSingleton = pb.PbConfig

	return err
}
Пример #6
0
func (bt *Generatorbeat) Config(b *beat.Beat) error {

	cfg := &config.GeneratorbeatConfig{}
	err := cfgfile.Read(&cfg, "")
	if err != nil {
		return fmt.Errorf("Error reading config file: %v", err)
	}

	for name, cfg := range cfg.Generators {
		factory, ok := generators[name]
		if !ok {
			return fmt.Errorf("Unknown generator: %v", name)
		}

		generators, err := factory(cfg)
		if err != nil {
			return err
		}

		for _, gen := range generators {
			bt.worker = append(bt.worker, &worker{
				done: bt.done,
				gen:  gen,
			})
		}
	}

	return nil
}
Пример #7
0
func TestReadConfig(t *testing.T) {
	absPath, err := filepath.Abs("../tests/files/")

	assert.NotNil(t, absPath)
	assert.Nil(t, err)

	config := &Config{}

	err = cfgfile.Read(config, absPath+"/config.yml")

	assert.Nil(t, err)

	assert.Equal(t, uint64(DefaultSpoolSize), config.Filebeat.SpoolSize)
	assert.Equal(t, "/prospectorConfigs/", config.Filebeat.ConfigDir)

	prospectors := config.Filebeat.Prospectors

	// Check if multiple paths were read in
	assert.Equal(t, 3, len(prospectors))

	// Check if full array can be read. Assumed that are ordered same as in config file
	assert.Equal(t, 2, len(prospectors[0].Paths))
	assert.Equal(t, "/var/log/s*.log", prospectors[0].Paths[1])
	assert.Equal(t, "log", prospectors[0].Input)
	assert.Equal(t, 3, len(prospectors[0].Harvester.Fields))
	assert.Equal(t, int64(1), prospectors[0].Harvester.Fields["review"])
	assert.Equal(t, "0", prospectors[0].IgnoreOlder)
	assert.Equal(t, "1h", prospectors[0].Harvester.CloseOlder)
	assert.Equal(t, "10s", prospectors[0].ScanFrequency)

	assert.Equal(t, "stdin", prospectors[2].Input)
	assert.Equal(t, 0, len(prospectors[2].Paths))
	assert.Equal(t, "", prospectors[1].ScanFrequency)
}
Пример #8
0
// LoadConfig inits the config file and reads the default config information
// into Beat.Config. It exists the processes in case of errors.
func (b *Beat) LoadConfig() error {

	err := cfgfile.Read(&b.Config, "")
	if err != nil {
		return fmt.Errorf("loading config file error: %v\n", err)
	}

	err = logp.Init(b.Name, &b.Config.Logging)
	if err != nil {
		return fmt.Errorf("error initializing logging: %v\n", err)
	}

	// Disable stderr logging if requested by cmdline flag
	logp.SetStderr()

	logp.Debug("beat", "Initializing output plugins")

	pub, err := publisher.New(b.Name, b.Config.Output, b.Config.Shipper)
	if err != nil {
		return fmt.Errorf("error Initialising publisher: %v\n", err)
	}

	b.Events = pub.Client()

	logp.Info("Init Beat: %s; Version: %s", b.Name, b.Version)

	return nil
}
Пример #9
0
func (eb *Winlogbeat) Config(b *beat.Beat) error {
	// Read configuration.
	err := cfgfile.Read(&eb.config, "")
	if err != nil {
		return fmt.Errorf("Error reading configuration file. %v", err)
	}

	// Validate configuration.
	err = eb.config.Winlogbeat.Validate()
	if err != nil {
		return fmt.Errorf("Error validating configuration file. %v", err)
	}
	debugf("Configuration validated. config=%v", eb.config)

	// Registry file grooming.
	if eb.config.Winlogbeat.RegistryFile == "" {
		eb.config.Winlogbeat.RegistryFile = config.DefaultRegistryFile
	}
	eb.config.Winlogbeat.RegistryFile, err = filepath.Abs(
		eb.config.Winlogbeat.RegistryFile)
	if err != nil {
		return fmt.Errorf("Error getting absolute path of registry file %s. %v",
			eb.config.Winlogbeat.RegistryFile, err)
	}
	logp.Info("State will be read from and persisted to %s",
		eb.config.Winlogbeat.RegistryFile)

	return nil
}
Пример #10
0
func (d *Dockerbeat) Config(b *beat.Beat) error {

	// Requires Docker 1.5 minimum
	d.minimalDockerVersion = SoftwareVersion{major: 1, minor: 5}

	err := cfgfile.Read(&d.TbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	//init the period
	if d.TbConfig.Input.Period != nil {
		d.period = time.Duration(*d.TbConfig.Input.Period) * time.Second
	} else {
		d.period = 1 * time.Second
	}
	//init the socket
	if d.TbConfig.Input.Socket != nil {
		d.socket = *d.TbConfig.Input.Socket
	} else {
		d.socket = "unix:///var/run/docker.sock" // default docker socket location
	}

	logp.Info("dockerbeat", "Init dockerbeat")
	logp.Info("dockerbeat", "Follow docker socket %q\n", d.socket)
	logp.Info("dockerbeat", "Period %v\n", d.period)

	return nil
}
Пример #11
0
func (d *Dockerbeat) Config(b *beat.Beat) error {

	err := cfgfile.Read(&d.TbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	//init the period
	if d.TbConfig.Input.Period != nil {
		d.period = time.Duration(*d.TbConfig.Input.Period) * time.Second
	} else {
		d.period = 1 * time.Second
	}
	//init the socket
	if d.TbConfig.Input.Socket != nil {
		d.socket = *d.TbConfig.Input.Socket
	} else {
		d.socket = "unix:///var/run/docker.sock" // default docker socket location
	}

	logp.Debug("dockerbeat", "Init dockerbeat")
	logp.Debug("dockerbeat", "Follow docker socket %q\n", d.socket)
	logp.Debug("dockerbeat", "Period %v\n", d.period)

	return nil
}
Пример #12
0
// LoadConfig inits the config file and reads the default config information
// into Beat.Config. It exists the processes in case of errors.
func (b *Beat) LoadConfig() {

	err := cfgfile.Read(&b.Config, "")
	if err != nil {
		// logging not yet initialized, so using fmt.Printf
		fmt.Printf("Loading config file error: %v\n", err)
		os.Exit(1)
	}

	err = logp.Init(b.Name, &b.Config.Logging)
	if err != nil {
		fmt.Printf("Error initializing logging: %v\n", err)
		os.Exit(1)
	}

	// Disable stderr logging if requested by cmdline flag
	logp.SetStderr()

	logp.Debug("beat", "Initializing output plugins")

	pub, err := publisher.New(b.Name, b.Config.Output, b.Config.Shipper)
	if err != nil {
		fmt.Printf("Error Initialising publisher: %v\n", err)
		logp.Critical(err.Error())
		os.Exit(1)
	}

	b.Events = pub.Client()

	logp.Info("Init Beat: %s; Version: %s", b.Name, b.Version)
}
Пример #13
0
func (ub *Unifiedbeat) Config(b *beat.Beat) error {
	// load the unifiedbeat.yml config file
	err := cfgfile.Read(&ub.UbConfig, "")
	if err != nil {
		return fmt.Errorf("Error reading config file: %v", err)
	}
	return nil
}
Пример #14
0
func (bt *Kafkabeat) Config(b *beat.Beat) error {

	// Load beater beatConfig
	logp.Info("Configuring Kafkabeat...")
	var err error
	err = cfgfile.Read(&bt.beatConfig, "")
	if err != nil {
		return fmt.Errorf("Error reading config file: %v", err)
	}

	bt.zookeepers = bt.beatConfig.Kafkabeat.Zookeepers
	if bt.zookeepers == nil || len(bt.zookeepers) == 0 {
		return KafkabeatError{"Atleast one zookeeper must be defined"}
	}
	zClient, err = kazoo.NewKazoo(bt.zookeepers, nil)
	if err != nil {
		logp.Err("Unable to connect to Zookeeper")
		return err
	}
	bt.brokers, err = zClient.BrokerList()
	if err != nil {
		logp.Err("Error identifying brokers from zookeeper")
		return err
	}
	if bt.brokers == nil || len(bt.brokers) == 0 {
		return KafkabeatError{"Unable to identify active brokers"}
	}
	logp.Info("Brokers: %v", bt.brokers)
	client, err = sarama.NewClient(bt.brokers, sarama.NewConfig())

	// Setting default period if not set
	if bt.beatConfig.Kafkabeat.Period == "" {
		bt.beatConfig.Kafkabeat.Period = "1s"
	}

	bt.period, err = time.ParseDuration(bt.beatConfig.Kafkabeat.Period)
	if err != nil {
		return err
	}
	bt.topics = bt.beatConfig.Kafkabeat.Topics
	bt.create_topic_docs = true
	if bt.topics == nil || len(bt.topics) == 0 {
		bt.create_topic_docs = bt.topics == nil
		bt.topics, err = client.Topics()
	}
	if err != nil {
		return err
	}
	logp.Info("Monitoring topics: %v", bt.topics)
	bt.groups = bt.beatConfig.Kafkabeat.Groups
	if bt.groups == nil {
		bt.groups, err = getGroups()
	}
	logp.Info("Monitoring groups %v", bt.groups)
	return err
}
Пример #15
0
func (bt *Govarbeat) Config(b *beat.Beat) error {

	// Load beater configuration
	err := cfgfile.Read(&bt.Configuration, "")
	if err != nil {
		return fmt.Errorf("Error reading config file: %v", err)
	}

	return nil
}
Пример #16
0
func (tb *Topbeat) Config(b *beat.Beat) error {

	err := cfgfile.Read(&tb.TbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	if tb.TbConfig.Input.Period != nil {
		tb.period = time.Duration(*tb.TbConfig.Input.Period) * time.Second
	} else {
		tb.period = 10 * time.Second
	}
	if tb.TbConfig.Input.Procs != nil {
		tb.procs = *tb.TbConfig.Input.Procs
	} else {
		tb.procs = []string{".*"} //all processes
	}

	if tb.TbConfig.Input.Stats.System != nil {
		tb.sysStats = *tb.TbConfig.Input.Stats.System
	} else {
		tb.sysStats = true
	}
	if tb.TbConfig.Input.Stats.Proc != nil {
		tb.procStats = *tb.TbConfig.Input.Stats.Proc
	} else {
		tb.procStats = true
	}
	if tb.TbConfig.Input.Stats.Filesystem != nil {
		tb.fsStats = *tb.TbConfig.Input.Stats.Filesystem
	} else {
		tb.fsStats = true
	}
	if tb.TbConfig.Input.Stats.CpuPerCore != nil {
		tb.cpuPerCore = *tb.TbConfig.Input.Stats.CpuPerCore
	} else {
		tb.cpuPerCore = false
	}

	if !tb.sysStats && !tb.procStats && !tb.fsStats {
		return errors.New("Invalid statistics configuration")
	}

	logp.Debug("topbeat", "Init topbeat")
	logp.Debug("topbeat", "Follow processes %q\n", tb.procs)
	logp.Debug("topbeat", "Period %v\n", tb.period)
	logp.Debug("topbeat", "System statistics %t\n", tb.sysStats)
	logp.Debug("topbeat", "Process statistics %t\n", tb.procStats)
	logp.Debug("topbeat", "File system statistics %t\n", tb.fsStats)
	logp.Debug("topbeat", "Cpu usage per core %t\n", tb.cpuPerCore)

	return nil
}
Пример #17
0
func (h *Httpbeat) Config(b *beat.Beat) error {

	err := cfgfile.Read(&h.HbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	logp.Info("httpbeat", "Init httpbeat")

	return nil
}
Пример #18
0
func (execBeat *Execbeat) Config(b *beat.Beat) error {

	err := cfgfile.Read(&execBeat.ExecConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	logp.Info("execbeat", "Init execbeat")

	return nil
}
Пример #19
0
func (nagiosCheckBeat *NagiosCheckBeat) Config(b *beat.Beat) error {
	var config config.ConfigSettings
	err := cfgfile.Read(&config, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	nagiosCheckBeat.checks = config.Input.Checks

	return nil
}
Пример #20
0
func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
	bt := &Httpbeat{
		done: make(chan bool),
	}

	err := cfgfile.Read(&bt.HbConfig, "")
	if err != nil {
		logp.Err("Error reading config file: %v", err)
		return nil, fmt.Errorf("Error reading config file: %v", err)
	}

	return bt, nil
}
Пример #21
0
// mergeConfigFiles reads in all config files given by list configFiles and merges them into config
func mergeConfigFiles(configFiles []string, config *Config) error {

	for _, file := range configFiles {
		logp.Info("Additional configs loaded from: %s", file)

		tmpConfig := &Config{}
		cfgfile.Read(tmpConfig, file)

		config.Filebeat.Prospectors = append(config.Filebeat.Prospectors, tmpConfig.Filebeat.Prospectors...)
	}

	return nil
}
Пример #22
0
func (mb *Metricbeat) Config(b *beat.Beat) error {

	mb.MbConfig = &Config{}
	err := cfgfile.Read(mb.MbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	// List all registered modules and metricsets
	include.ListAll()

	return nil
}
Пример #23
0
func (fb *Factbeat) Config(b *beat.Beat) error {
	err := cfgfile.Read(&fb.FbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	if fb.FbConfig.Input.Period != nil {
		fb.period = time.Duration(*fb.FbConfig.Input.Period) * time.Second
	} else {
		fb.period = 60 * time.Second
	}
	return nil
}
Пример #24
0
// Config setups up the filebeat configuration by fetch all additional config files
func (fb *Filebeat) Config(b *beat.Beat) error {

	// Load Base config
	err := cfgfile.Read(&fb.FbConfig, "")

	if err != nil {
		return fmt.Errorf("Error reading config file: %v", err)
	}

	// Check if optional config_dir is set to fetch additional prospector config files
	fb.FbConfig.FetchConfigs()

	return nil
}
Пример #25
0
func TestReadConfig2(t *testing.T) {
	// Tests with different params from config file
	absPath, err := filepath.Abs("../tests/files/")

	assert.NotNil(t, absPath)
	assert.Nil(t, err)

	config := &Config{}

	// Reads second config file
	err = cfgfile.Read(config, absPath+"/config2.yml")
	assert.Nil(t, err)

	assert.Equal(t, uint64(0), config.Filebeat.SpoolSize)
}
Пример #26
0
func TestReadConfig(t *testing.T) {
	absPath, err := filepath.Abs("../tests/files/")

	assert.NotNil(t, absPath)
	assert.Nil(t, err)

	config := &ConfigSettings{}

	err = cfgfile.Read(config, absPath+"/config.yml")
	assert.Nil(t, err)

	urls := config.Httpbeat.Urls
	assert.Equal(t, 2, len(urls))

	assert.Equal(t, "http://example.org/1", urls[0].Url)
	assert.Equal(t, "get", urls[0].Method)
	assert.Equal(t, "@every 1m", urls[0].Cron)
	assert.Equal(t, "body", urls[0].Body)
	assert.Equal(t, "foo1", urls[0].BasicAuth.Username)
	assert.Equal(t, "bar1", urls[0].BasicAuth.Password)
	assert.Equal(t, "http://*****:*****@every 2m", urls[1].Cron)
	assert.Equal(t, "", urls[1].BasicAuth.Username)
	assert.Equal(t, "", urls[1].BasicAuth.Password)
	assert.Equal(t, "", urls[1].ProxyUrl)
	assert.Equal(t, 0, len(urls[1].Headers))
	assert.Equal(t, 0, len(urls[1].Fields))
	assert.Equal(t, "", urls[1].DocumentType)
}
Пример #27
0
func (fb *Flowbeat) Config(b *beat.Beat) error {

	err := cfgfile.Read(&fb.FbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	if fb.FbConfig.Input.Listen != nil {
		fb.listen = *fb.FbConfig.Input.Listen
	} else {
		fb.listen = ":6343"
	}

	logp.Debug("flowbeat", "Init flowbeat")
	logp.Debug("flowbeat", "Listening on %s\n", fb.listen)

	return nil
}
Пример #28
0
func (mb *Modbeat) Config(b *beat.Beat) error {

	cfg := &config.ModbeatConfig{}
	err := cfgfile.Read(&cfg, "")
	if err != nil {
		return fmt.Errorf("Error reading config file: %v", err)
	}

	// Start all scanners
	for _, pathConfig := range cfg.Modbeat.Paths {
		// TODO: Handle proper shutdown -> waitgroups and done channel
		go func(pathConfig config.PathConfig) {
			mod.Scanner(pathConfig, b.Events)
		}(pathConfig)
	}

	<-mb.done

	return nil
}
Пример #29
0
func (bt *Dockbeat) Config(b *beat.Beat) error {

	// Requires Docker 1.9 minimum
	bt.minimalDockerVersion = SoftwareVersion{major: 1, minor: 9}

	err := cfgfile.Read(&bt.beatConfig, "")
	if err != nil {
		logp.Err("dockbeat", "Error reading configuration file: %v", err)
		return err
	}

	//init the period
	if bt.beatConfig.Dockbeat.Period != nil {
		bt.period = time.Duration(*bt.beatConfig.Dockbeat.Period) * time.Second
	} else {
		bt.period = 1 * time.Second
	}
	//init the socketConfig
	bt.socketConfig = SocketConfig{
		socket:    "",
		enableTls: false,
		caPath:    "",
		certPath:  "",
		keyPath:   "",
	}

	if bt.beatConfig.Dockbeat.Socket != nil {
		bt.socketConfig.socket = *bt.beatConfig.Dockbeat.Socket
	} else {
		bt.socketConfig.socket = "unix:///var/run/docker.sock" // default docker socket location
	}
	if bt.beatConfig.Dockbeat.Tls.Enable != nil {
		bt.socketConfig.enableTls = *bt.beatConfig.Dockbeat.Tls.Enable
	} else {
		bt.socketConfig.enableTls = false
	}
	if bt.socketConfig.enableTls {
		if bt.beatConfig.Dockbeat.Tls.CaPath != nil {
			bt.socketConfig.caPath = *bt.beatConfig.Dockbeat.Tls.CaPath
		}
		if bt.beatConfig.Dockbeat.Tls.CertPath != nil {
			bt.socketConfig.certPath = *bt.beatConfig.Dockbeat.Tls.CertPath
		}
		if bt.beatConfig.Dockbeat.Tls.KeyPath != nil {
			bt.socketConfig.keyPath = *bt.beatConfig.Dockbeat.Tls.KeyPath
		}
	}

	// init the stats statsConfig
	bt.statsConfig = StatsConfig{
		Container: true,
		Net:       true,
		Memory:    true,
		Blkio:     true,
		Cpu:       true,
	}

	if bt.beatConfig.Dockbeat.Stats.Container != nil && !*bt.beatConfig.Dockbeat.Stats.Container {
		bt.statsConfig.Container = false
	}
	if bt.beatConfig.Dockbeat.Stats.Net != nil && !*bt.beatConfig.Dockbeat.Stats.Net {
		bt.statsConfig.Net = false
	}
	if bt.beatConfig.Dockbeat.Stats.Memory != nil && !*bt.beatConfig.Dockbeat.Stats.Memory {
		bt.statsConfig.Memory = false
	}
	if bt.beatConfig.Dockbeat.Stats.Blkio != nil && !*bt.beatConfig.Dockbeat.Stats.Blkio {
		bt.statsConfig.Blkio = false
	}
	if bt.beatConfig.Dockbeat.Stats.Cpu != nil && !*bt.beatConfig.Dockbeat.Stats.Cpu {
		bt.statsConfig.Cpu = false
	}

	logp.Info("dockbeat", "Init dockbeat")
	logp.Info("dockbeat", "Follow docker socket %v\n", bt.socketConfig.socket)
	if bt.socketConfig.enableTls {
		logp.Info("dockbeat", "TLS enabled\n")
	} else {
		logp.Info("dockbeat", "TLS disabled\n")
	}
	logp.Info("dockbeat", "Period %v\n", bt.period)

	return nil
}
Пример #30
0
func (rb *Redisbeat) Config(b *beat.Beat) error {

	err := cfgfile.Read(&rb.RbConfig, "")
	if err != nil {
		logp.Err("Error reading configuration file: %v", err)
		return err
	}

	if rb.RbConfig.Input.Period != nil {
		rb.period = time.Duration(*rb.RbConfig.Input.Period) * time.Second
	} else {
		rb.period = DEFAULT_PERIOD
	}

	if rb.RbConfig.Input.Host != nil {
		rb.host = *rb.RbConfig.Input.Host
	} else {
		rb.host = DEFAULT_HOST
	}

	if rb.RbConfig.Input.Port != nil {
		rb.port = *rb.RbConfig.Input.Port
	} else {
		rb.port = DEFAULT_PORT
	}

	if rb.RbConfig.Input.Network != nil {
		rb.network = *rb.RbConfig.Input.Network
	} else {
		rb.network = DEFAULT_NETWORK
	}

	if rb.RbConfig.Input.MaxConn != nil {
		rb.maxConn = *rb.RbConfig.Input.MaxConn
	} else {
		rb.maxConn = DEFAULT_MAX_CONN
	}

	if rb.RbConfig.Input.Auth.Required != nil {
		rb.auth = *rb.RbConfig.Input.Auth.Required
	} else {
		rb.auth = DEFAULT_AUTH_REQUIRED
	}

	if rb.RbConfig.Input.Auth.RequiredPass != nil {
		rb.pass = *rb.RbConfig.Input.Auth.RequiredPass
	} else {
		rb.pass = DEFAULT_AUTH_REQUIRED_PASS
	}

	if rb.RbConfig.Input.Stats.Server != nil {
		rb.serverStats = *rb.RbConfig.Input.Stats.Server
	} else {
		rb.serverStats = DEFAULT_STATS_SERVER
	}

	if rb.RbConfig.Input.Stats.Clients != nil {
		rb.clientsStats = *rb.RbConfig.Input.Stats.Clients
	} else {
		rb.clientsStats = DEFAULT_STATS_CLIENT
	}

	if rb.RbConfig.Input.Stats.Memory != nil {
		rb.memoryStats = *rb.RbConfig.Input.Stats.Memory
	} else {
		rb.memoryStats = DEFAULT_STATS_MEMORY
	}

	if rb.RbConfig.Input.Stats.Persistence != nil {
		rb.persistenceStats = *rb.RbConfig.Input.Stats.Persistence
	} else {
		rb.persistenceStats = DEFAULT_STATS_PERSISTENCE
	}

	if rb.RbConfig.Input.Stats.Stats != nil {
		rb.statsStats = *rb.RbConfig.Input.Stats.Stats
	} else {
		rb.statsStats = DEFAULT_STATS_STATS
	}

	if rb.RbConfig.Input.Stats.Replication != nil {
		rb.replicationStats = *rb.RbConfig.Input.Stats.Replication
	} else {
		rb.replicationStats = DEFAULT_STATS_REPLICATION
	}

	if rb.RbConfig.Input.Stats.Cpu != nil {
		rb.cpuStats = *rb.RbConfig.Input.Stats.Cpu
	} else {
		rb.cpuStats = DEFAULT_STATS_CPU
	}

	if rb.RbConfig.Input.Stats.Commandstats != nil {
		rb.commandStats = *rb.RbConfig.Input.Stats.Commandstats
	} else {
		rb.commandStats = DEFAULT_STATS_COMMAND
	}

	if rb.RbConfig.Input.Stats.Cluster != nil {
		rb.clusterStats = *rb.RbConfig.Input.Stats.Cluster
	} else {
		rb.clusterStats = DEFAULT_STATS_CLUSTER
	}

	if rb.RbConfig.Input.Stats.Keyspace != nil {
		rb.keyspaceStats = *rb.RbConfig.Input.Stats.Keyspace
	} else {
		rb.keyspaceStats = DEFAULT_STATS_KEYSPACE
	}

	logp.Debug("redisbeat", "Init redisbeat")
	logp.Debug("redisbeat", "Period %v\n", rb.period)
	logp.Debug("redisbeat", "Host %v\n", rb.host)
	logp.Debug("redisbeat", "Port %v\n", rb.port)
	logp.Debug("redisbeat", "Network %v\n", rb.network)
	logp.Debug("redisbeat", "Max Connections %v\n", rb.maxConn)
	logp.Debug("redisbeat", "Auth %t\n", rb.auth)
	logp.Debug("redisbeat", "Server statistics %t\n", rb.serverStats)
	logp.Debug("redisbeat", "Client statistics %t\n", rb.clientsStats)
	logp.Debug("redisbeat", "Memory statistics %t\n", rb.memoryStats)
	logp.Debug("redisbeat", "Persistence statistics %t\n", rb.persistenceStats)
	logp.Debug("redisbeat", "Stats statistics %t\n", rb.statsStats)
	logp.Debug("redisbeat", "Replication statistics %t\n", rb.replicationStats)
	logp.Debug("redisbeat", "Cpu statistics %t\n", rb.cpuStats)
	logp.Debug("redisbeat", "Command statistics %t\n", rb.commandStats)
	logp.Debug("redisbeat", "Cluster statistics %t\n", rb.clusterStats)
	logp.Debug("redisbeat", "Keyspace statistics %t\n", rb.keyspaceStats)

	return nil
}