Skip to content

Commit

Permalink
Merge pull request elastic#4 from ruflin/config-file
Browse files Browse the repository at this point in the history
Renamed -config param to -configDir and make it optional. Everything …
  • Loading branch information
tsg committed Sep 11, 2015
2 parents d94efce + 47c1e05 commit ebb781f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clean:

.PHONY: run
run: build
./filebeat -c etc/filebeat.yml -config etc/filebeat.yml -e -v
./filebeat -c etc/filebeat.yml -e -v

.PHONY: test
test:
Expand Down
26 changes: 16 additions & 10 deletions beat/filebeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/elastic/libbeat/logp"
"os"
"time"
"github.com/elastic/libbeat/cfgfile"
)

var exitStat = struct {
Expand All @@ -21,12 +22,11 @@ var exitStat = struct {
faulted: 2,
}

var configPath string
var configDirPath string

// Init config path flag
// TODO: This should be merged with the beat config
func init() {
flag.StringVar(&configPath, "config", configPath, "path to logstash-forwarder configuration file or directory")
flag.StringVar(&configDirPath, "configDir", "", "path to additional filebeat configuration directory with .yml files")
}

// Beater object. Contains all objects needed to run the beat
Expand All @@ -40,15 +40,21 @@ type Filebeat struct {

// Config setups up the filebeat configuration by fetch all additional config files
func (fb *Filebeat) Config(b *beat.Beat) error {
// Check if config set
if configPath == "" {
fmt.Println("fatal: config file must be defined")
os.Exit(exitStat.usageError)
}

emitOptions()

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

if err != nil {
logp.Warn("Error reading config file:", err)
}

// This is optiona
if configDirPath != "" {
logp.Info("Additional config files are fetched from:", configDirPath)
fb.FbConfig.FetchConfigs(configDirPath)
}

return nil
}
Expand Down Expand Up @@ -106,7 +112,7 @@ func (fb *Filebeat) Stop() {
// emitOptions prints out the set config options
func emitOptions() {
logp.Info("filebeat", "\t--- options -------")
logp.Info("filebeat", "\tconfig-arg: %s", configPath)
logp.Info("filebeat", "\tconfig-arg: %s", configDirPath)
logp.Info("filebeat", "\tidle-timeout: %v", cfg.CmdlineOptions.IdleTimeout)
logp.Info("filebeat", "\tspool-size: %d", cfg.CmdlineOptions.SpoolSize)
logp.Info("filebeat", "\tharvester-buff-size: %d", cfg.CmdlineOptions.HarvesterBufferSize)
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var defaultConfig = &struct {
* All command line options were also translated to config files options
* Getting config from env was removed. I think a better method like getting it from es should be used: https://github.com/elastic/logstash-forwarder/pull/435
* What should we do about multiple configs? Just provide some docs? https://github.com/elastic/logstash-forwarder/issues/136 currently working with -c for beat -config for dirs
* Command line config option -config was renamed to configDir. Should also be introduced as config file param in case we want to keep it

Notes:
* Should every config entry have a name -> make it possible to know from which config entry something comes.
Expand Down
7 changes: 2 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ func mergeConfigFiles(configFiles []string, config *Config) error {
}

// Fetches and merges all config files given by Options.configArgs. All are put into one config object
func FetchConfigs(path string) *Config {

config := &Config{}
func (config *Config) FetchConfigs(path string) {

configFiles, err := getConfigFiles(path)

if err != nil {
log.Fatal("Could not use -config of ", path, err)
log.Fatal("Could not use -configDir of ", path, err)
}

err = mergeConfigFiles(configFiles, config)
Expand All @@ -124,5 +122,4 @@ func FetchConfigs(path string) *Config {
log.Fatalf("No paths given. What files do you want me to watch?")
}

return config
}

0 comments on commit ebb781f

Please sign in to comment.