diff --git a/config/config.go b/config/config.go index a080bc16825..ad64be8f66c 100644 --- a/config/config.go +++ b/config/config.go @@ -1,25 +1,30 @@ package config -import "github.com/BurntSushi/toml" +import ( + "github.com/BurntSushi/toml" + "github.com/elastic/infrabeat/common/droppriv" + "github.com/elastic/infrabeat/outputs" + "github.com/elastic/packetbeat/procs" +) type Config struct { Interfaces InterfacesConfig Protocols map[string]Protocol - //Output map[string]MothershipConfig - Input Input - //RunOptions RunOptions - //Procs Procs - //Agent Agent - Logging Logging - Passwords Passwords - Thrift Thrift - Http Http - Mysql Mysql - Pgsql Pgsql - //Geoip Geoip - Udpjson Udpjson - GoBeacon GoBeacon - Filter map[string]interface{} + Output map[string]outputs.MothershipConfig + Agent outputs.AgentConfig + Input Input + Procs procs.ProcsConfig + RunOptions droppriv.RunOptions + Logging Logging + Passwords Passwords + Thrift Thrift + Http Http + Mysql Mysql + Pgsql Pgsql + Geoip outputs.Geoip + Udpjson Udpjson + GoBeacon GoBeacon + Filter map[string]interface{} } type InterfacesConfig struct { diff --git a/main.go b/main.go index 7c657a974b8..ad89feda494 100644 --- a/main.go +++ b/main.go @@ -113,12 +113,6 @@ func main() { return } - var cfg common.Config - if cfg.Meta, err = toml.DecodeFile(*configfile, &cfg.Options); err != nil { - fmt.Printf("TOML config parsing failed on %s: %s. Exiting.\n", *configfile, err) - return - } - if len(debugSelectors) == 0 { debugSelectors = config.ConfigSingleton.Logging.Selectors } @@ -143,18 +137,19 @@ func main() { } logp.Debug("main", "Initializing output plugins") - if err = outputs.Publisher.Init(*publishDisabled, cfg); err != nil { + if err = outputs.Publisher.Init(*publishDisabled, config.ConfigSingleton.Output, + config.ConfigSingleton.Agent); err != nil { logp.Critical(err.Error()) return } - if err = procs.ProcWatcher.Init(cfg); err != nil { + if err = procs.ProcWatcher.Init(config.ConfigSingleton.Procs); err != nil { logp.Critical(err.Error()) return } - err = outputs.LoadGeoIPData(cfg) + err = outputs.LoadGeoIPData(config.ConfigSingleton.Geoip, config.ConfigMeta) if err != nil { logp.Critical(err.Error()) return @@ -212,7 +207,7 @@ func main() { } // This needs to be after the sniffer Init but before the sniffer Run. - if err = droppriv.DropPrivileges(cfg); err != nil { + if err = droppriv.DropPrivileges(config.ConfigSingleton.RunOptions, config.ConfigMeta); err != nil { logp.Critical(err.Error()) return } diff --git a/procs/procs.go b/procs/procs.go index 07e794b2192..4ef6f1f8d80 100644 --- a/procs/procs.go +++ b/procs/procs.go @@ -15,7 +15,6 @@ import ( "strings" "time" - "github.com/BurntSushi/toml" "github.com/elastic/infrabeat/common" "github.com/elastic/infrabeat/logp" ) @@ -54,8 +53,6 @@ type ProcessesWatcher struct { ReadFromProc bool MaxReadFreq time.Duration RefreshPidsFreq time.Duration - Config ProcsConfig - ConfigMeta toml.MetaData // test helpers proc_prefix string @@ -75,23 +72,13 @@ type ProcConfig struct { var ProcWatcher ProcessesWatcher -func (proc *ProcessesWatcher) Init(cfg common.Config) error { - - proc.ConfigMeta = cfg.Meta - var config struct { - Procs ProcsConfig - } - err := common.DecodeConfig(cfg, &config) - if err != nil { - return nil - } - proc.Config = config.Procs +func (proc *ProcessesWatcher) Init(config ProcsConfig) error { proc.proc_prefix = "" proc.PortProcMap = make(map[uint16]PortProcMapping) proc.LastMapUpdate = time.Now() - proc.ReadFromProc = !proc.Config.Dont_read_from_proc + proc.ReadFromProc = !config.Dont_read_from_proc if proc.ReadFromProc { if runtime.GOOS != "linux" { proc.ReadFromProc = false @@ -99,21 +86,22 @@ func (proc *ProcessesWatcher) Init(cfg common.Config) error { } } - if proc.Config.Max_proc_read_freq == 0 { + if config.Max_proc_read_freq == 0 { proc.MaxReadFreq = 10 * time.Millisecond } else { - proc.MaxReadFreq = time.Duration(proc.Config.Max_proc_read_freq) * + proc.MaxReadFreq = time.Duration(config.Max_proc_read_freq) * time.Millisecond } - if proc.Config.Refresh_pids_freq == 0 { + if config.Refresh_pids_freq == 0 { proc.RefreshPidsFreq = 1 * time.Second } else { - proc.RefreshPidsFreq = time.Duration(proc.Config.Refresh_pids_freq) * + proc.RefreshPidsFreq = time.Duration(config.Refresh_pids_freq) * time.Millisecond } // Read the local IP addresses + var err error proc.LocalAddrs, err = common.LocalIpAddrs() if err != nil { logp.Err("Error getting local IP addresses: %s", err) @@ -121,7 +109,7 @@ func (proc *ProcessesWatcher) Init(cfg common.Config) error { } if proc.ReadFromProc { - for pstr, procConfig := range proc.Config.Monitored { + for pstr, procConfig := range config.Monitored { grepper := procConfig.Cmdline_grep if len(grepper) == 0 {