func new(beatName string, cfg *common.Config, _ int) (outputs.Outputer, error) { if !cfg.HasField("index") { cfg.SetString("index", -1, beatName) } output := &logstash{} if err := output.init(cfg); err != nil { return nil, err } return output, nil }
// New instantiates a new output plugin instance publishing to elasticsearch. func New(beatName string, cfg *common.Config, topologyExpire int) (outputs.Outputer, error) { if !cfg.HasField("bulk_max_size") { cfg.SetInt("bulk_max_size", -1, defaultBulkSize) } if !cfg.HasField("index") { pattern := fmt.Sprintf("%v-%%{+yyyy.MM.dd}", beatName) cfg.SetString("index", -1, pattern) } output := &elasticsearchOutput{beatName: beatName} err := output.init(cfg, topologyExpire) if err != nil { return nil, err } return output, nil }
func (r *redisOut) init(cfg *common.Config, expireTopo int) error { config := defaultConfig if err := cfg.Unpack(&config); err != nil { return err } sendRetries := config.MaxRetries maxAttempts := config.MaxRetries + 1 if sendRetries < 0 { maxAttempts = 0 } var dataType redisDataType switch config.DataType { case "", "list": dataType = redisListType case "channel": dataType = redisChannelType default: return errors.New("Bad Redis data type") } if cfg.HasField("index") && !cfg.HasField("key") { s, err := cfg.String("index", -1) if err != nil { return err } if err := cfg.SetString("key", -1, s); err != nil { return err } } if !cfg.HasField("key") { cfg.SetString("key", -1, r.beatName) } key, err := outil.BuildSelectorFromConfig(cfg, outil.Settings{ Key: "key", MultiKey: "keys", EnableSingleOnly: true, FailEmpty: true, }) if err != nil { return err } tls, err := outputs.LoadTLSConfig(config.TLS) if err != nil { return err } transp := &transport.Config{ Timeout: config.Timeout, Proxy: &config.Proxy, TLS: tls, Stats: &transport.IOStats{ Read: statReadBytes, Write: statWriteBytes, ReadErrors: statReadErrors, WriteErrors: statWriteErrors, }, } // configure topology support r.topology.init(transp, topoConfig{ host: config.HostTopology, password: config.PasswordTopology, db: config.DbTopology, expire: time.Duration(expireTopo) * time.Second, }) // configure publisher clients clients, err := modeutil.MakeClients(cfg, func(host string) (mode.ProtocolClient, error) { t, err := transport.NewClient(transp, "tcp", host, config.Port) if err != nil { return nil, err } return newClient(t, config.Password, config.Db, key, dataType), nil }) if err != nil { return err } logp.Info("Max Retries set to: %v", sendRetries) m, err := modeutil.NewConnectionMode(clients, modeutil.Settings{ Failover: !config.LoadBalance, MaxAttempts: maxAttempts, Timeout: config.Timeout, WaitRetry: defaultWaitRetry, MaxWaitRetry: defaultMaxWaitRetry, }) if err != nil { return err } r.mode = m return nil }