本文整理匯總了Golang中github.com/elastic/libbeat/cfgfile.Read函數的典型用法代碼示例。如果您正苦於以下問題:Golang Read函數的具體用法?Golang Read怎麽用?Golang Read使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Read函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Config
// 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
}
示例2: TestReadConfig
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(1024), 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, 1, len(prospectors[0].Harvester.Fields["review"]))
assert.Equal(t, "24h", prospectors[0].IgnoreOlder)
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)
}
示例3: Config
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 = 1 * time.Second
}
if tb.TbConfig.Input.Procs != nil {
tb.procs = *tb.TbConfig.Input.Procs
} else {
tb.procs = []string{".*"} //all processes
}
logp.Debug("topbeat", "Init toppbeat")
logp.Debug("topbeat", "Follow processes %q\n", tb.procs)
logp.Debug("topbeat", "Period %v\n", tb.period)
return nil
}
示例4: Config
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
}
示例5: LoadConfig
// 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("%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)
}
logp.Debug("beat", "Initializing output plugins")
if err := publisher.Publisher.Init(b.Name, b.Version, b.Config.Output, b.Config.Shipper); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
b.Events = publisher.Publisher.Client()
logp.Debug("beat", "Init %s", b.Name)
}
示例6: TestReadConfig
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)
files := config.Filebeat.Files
// Check if multiple paths were read in
assert.Equal(t, 3, len(files))
// Check if full array can be read. Assumed that are ordered same as in config file
assert.Equal(t, 2, len(files[0].Paths))
assert.Equal(t, "/var/log/s*.log", files[0].Paths[1])
assert.Equal(t, "log", files[0].Input)
assert.Equal(t, 3, len(files[0].Fields))
assert.Equal(t, 1, len(files[0].Fields["review"]))
assert.Equal(t, "24h", files[0].IgnoreOlder)
assert.Equal(t, "stdin", files[2].Input)
assert.Equal(t, 0, len(files[2].Paths))
}
示例7: Config
// Config Uwsgibeat according to uwsgibeat.yml.
func (ub *Uwsgibeat) Config(b *beat.Beat) error {
err := cfgfile.Read(&ub.UbConfig, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
var u string
if ub.UbConfig.Input.URL != "" {
u = ub.UbConfig.Input.URL
} else {
u = "127.0.0.1:1717"
}
ub.url, err = url.Parse(u)
if err != nil {
logp.Err("Invalid uWSGI stats server address: %v", err)
return err
}
if ub.UbConfig.Input.Period != nil {
ub.period = time.Duration(*ub.UbConfig.Input.Period) * time.Second
} else {
ub.period = 1 * time.Second
}
logp.Debug(selector, "Init uwsgibeat")
logp.Debug(selector, "Watch %v", ub.url)
logp.Debug(selector, "Period %v", ub.period)
return nil
}
示例8: ConfigSetup
func (beat *Beat) ConfigSetup(beater Beater, inputConfig interface{}) {
config := &ConfigSettings{
//Input: inputConfig,
}
err := cfgfile.Read(config)
beat.Config = *config
if err != nil {
logp.Debug("Log read error", "Error %v\n", err)
}
logp.Init(beat.Name, &beat.Config.Logging)
logp.Debug("main", "Initializing output plugins")
if err := publisher.Publisher.Init(beat.Config.Output, beat.Config.Shipper); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
beat.events = publisher.Publisher.Queue
logp.Debug(beat.Name, "Init %s", beat.Name)
if err := beater.Init(beat); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
}
示例9: Config
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: LoadConfig
// 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")
if err := publisher.Publisher.Init(b.Name, b.Config.Output, b.Config.Shipper); err != nil {
fmt.Printf("Error Initialising publisher: %v\n", err)
logp.Critical(err.Error())
os.Exit(1)
}
b.Events = publisher.Publisher.Client()
logp.Debug("beat", "Init %s", b.Name)
}
示例11: Config
// Config Gzipbeat according to gzipbeat.yml.
func (gb *Gzipbeat) Config(b *beat.Beat) error {
err := cfgfile.Read(&gb.config, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
return nil
}
示例12: Config
func (p *Pingbeat) Config(b *beat.Beat) error {
// Read in provided config file, bail if problem
err := cfgfile.Read(&p.config, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
// Use period provided in config or default to 5s
if p.config.Input.Period != nil {
p.period = time.Duration(*p.config.Input.Period) * time.Second
} else {
p.period = 5 * time.Second
}
logp.Debug("pingbeat", "Period %v\n", p.period)
// Check if we can use privileged (i.e. raw socket) ping,
// else use a UDP ping
if *p.config.Input.Privileged {
p.pingType = "ip"
} else {
p.pingType = "udp"
}
logp.Debug("pingbeat", "Using %v for pings\n", p.pingType)
// Check whether IPv4/IPv6 pings are requested in config
// Default to just IPv4 pings
if &p.config.Input.UseIPv4 != nil {
p.useIPv4 = *p.config.Input.UseIPv4
} else {
p.useIPv4 = true
}
if &p.config.Input.UseIPv6 != nil {
p.useIPv6 = *p.config.Input.UseIPv6
} else {
p.useIPv6 = false
}
logp.Debug("pingbeat", "IPv4: %v, IPv6: %v\n", p.useIPv4, p.useIPv6)
// Fill the IPv4/IPv6 targets maps
p.ipv4targets = make(map[string][2]string)
p.ipv6targets = make(map[string][2]string)
if p.config.Input.Targets != nil {
for tag, targets := range *p.config.Input.Targets {
for i := 0; i < len(targets); i++ {
p.AddTarget(targets[i], tag)
}
}
} else {
logp.Critical("Error: no targets specified, cannot continue!")
os.Exit(1)
}
return nil
}
示例13: mergeConfigFiles
// 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 {
tmpConfig := &Config{}
cfgfile.Read(tmpConfig, file)
config.Filebeat.Files = append(config.Filebeat.Files, tmpConfig.Filebeat.Files...)
}
return nil
}
示例14: Config
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
}
示例15: TestJournalCfgIsOptional
func TestJournalCfgIsOptional(t *testing.T) {
var settings Settings
cfgfile.Read(&settings, "./testfiles/minimal.yml")
err := settings.SetDefaults()
assert.Nil(t, err, fmt.Sprintf("Unexected error %v", err))
jcfg := settings.AmqpInput.Journal
assert.NotNil(t, jcfg, "JournalConfig be populated with defaults")
assert.NotNil(t, jcfg.BufferSizeBlocks)
assert.NotNil(t, jcfg.JournalDir)
assert.NotNil(t, jcfg.MaxDelayMs)
assert.NotNil(t, jcfg.MaxFileSizeBytes)
}