Exemple #1
0
// NewOutput instantiates a new output plugin instance publishing to elasticsearch.
func (f elasticsearchOutputPlugin) NewOutput(
	beat string,
	config *outputs.MothershipConfig,
	topologyExpire int,
) (outputs.Outputer, error) {

	// configure bulk size in config in case it is not set
	if config.BulkMaxSize == nil {
		bulkSize := defaultBulkSize
		config.BulkMaxSize = &bulkSize
	}

	output := &elasticsearchOutput{}
	err := output.init(beat, *config, topologyExpire)
	if err != nil {
		return nil, err
	}
	return output, nil
}
Exemple #2
0
func (out *fileOutput) init(beat string, config *outputs.MothershipConfig, topology_expire int) error {
	out.rotator.Path = config.Path
	out.rotator.Name = config.Filename
	if out.rotator.Name == "" {
		out.rotator.Name = beat
	}
	logp.Info("File output base filename set to: %v", out.rotator.Name)

	// disable bulk support
	configDisableInt := -1
	config.FlushInterval = &configDisableInt
	config.BulkMaxSize = &configDisableInt

	rotateeverybytes := uint64(config.RotateEveryKb) * 1024
	if rotateeverybytes == 0 {
		rotateeverybytes = 10 * 1024 * 1024
	}
	logp.Info("Rotate every bytes set to: %v", rotateeverybytes)
	out.rotator.RotateEveryBytes = &rotateeverybytes

	keepfiles := config.NumberOfFiles
	if keepfiles == 0 {
		keepfiles = 7
	}
	logp.Info("Number of files set to: %v", keepfiles)

	out.rotator.KeepFiles = &keepfiles

	err := out.rotator.CreateDirectory()
	if err != nil {
		return err
	}

	err = out.rotator.CheckIfConfigSane()
	if err != nil {
		return err
	}

	return nil
}
Exemple #3
0
func (out *elasticsearchOutput) init(
	beat string,
	config outputs.MothershipConfig,
	topologyExpire int,
) error {
	tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
	if err != nil {
		return err
	}

	// configure bulk size in config in case it is not set
	if config.BulkMaxSize == nil {
		bulkSize := defaultBulkSize
		config.BulkMaxSize = &bulkSize
	}

	clients, err := mode.MakeClients(config, makeClientFactory(beat, tlsConfig, config))
	if err != nil {
		return err
	}

	timeout := elasticsearchDefaultTimeout
	if config.Timeout != 0 {
		timeout = time.Duration(config.Timeout) * time.Second
	}

	maxRetries := defaultMaxRetries
	if config.Max_retries != nil {
		maxRetries = *config.Max_retries
	}

	var waitRetry = time.Duration(1) * time.Second
	var maxWaitRetry = time.Duration(60) * time.Second

	var m mode.ConnectionMode
	out.clients = clients
	if len(clients) == 1 {
		client := clients[0]
		m, err = mode.NewSingleConnectionMode(client, maxRetries,
			waitRetry, timeout, maxWaitRetry)
	} else {
		loadBalance := config.LoadBalance == nil || *config.LoadBalance
		if loadBalance {
			m, err = mode.NewLoadBalancerMode(clients, maxRetries,
				waitRetry, timeout, maxWaitRetry)
		} else {
			m, err = mode.NewFailOverConnectionMode(clients, maxRetries, waitRetry, timeout)
		}
	}
	if err != nil {
		return err
	}

	if config.Save_topology {
		err := out.EnableTTL()
		if err != nil {
			logp.Err("Fail to set _ttl mapping: %s", err)
			// keep trying in the background
			go func() {
				for {
					err := out.EnableTTL()
					if err == nil {
						break
					}
					logp.Err("Fail to set _ttl mapping: %s", err)
					time.Sleep(5 * time.Second)
				}
			}()
		}
	}

	out.TopologyExpire = 15000
	if topologyExpire != 0 {
		out.TopologyExpire = topologyExpire * 1000 // millisec
	}

	out.mode = m
	if config.Index != "" {
		out.index = config.Index
	} else {
		out.index = beat
	}
	return nil
}