Skip to content

Commit

Permalink
Pass the config options to Infrabeat packages
Browse files Browse the repository at this point in the history
- Fix #1
- Keep all the config options in beats and pass to Infrabeat packages
the ones requested by each package
  • Loading branch information
monicasarbu committed Apr 6, 2015
1 parent 025693f commit 0bb7254
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 46 deletions.
37 changes: 21 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
15 changes: 5 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
28 changes: 8 additions & 20 deletions procs/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"strings"
"time"

"github.com/BurntSushi/toml"
"github.com/elastic/infrabeat/common"
"github.com/elastic/infrabeat/logp"
)
Expand Down Expand Up @@ -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
Expand All @@ -75,53 +72,44 @@ 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
logp.Info("Disabled /proc/ reading because not on linux")
}
}

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)
proc.LocalAddrs = []net.IP{}
}

if proc.ReadFromProc {
for pstr, procConfig := range proc.Config.Monitored {
for pstr, procConfig := range config.Monitored {

grepper := procConfig.Cmdline_grep
if len(grepper) == 0 {
Expand Down

0 comments on commit 0bb7254

Please sign in to comment.