Exemplo n.º 1
0
func (i *TailInput) Init(env *plugin.Env) (err error) {
	i.env = env
	i.conf = &Config{}
	i.watchers = make(map[string]*Watcher)
	if err = env.ReadConfig(i.conf); err != nil {
		return
	}
	if i.conf.TimeKey == "" {
		i.conf.TimeKey = "time"
	}
	i.parser, i.timeParser, err = parser.Get(i.conf.Format, i.conf.TimeFormat, i.conf.TimeZone)
	if err != nil {
		return
	}
	if i.conf.RecordKey != "" {
		if i.rparser, _, err = parser.Get(i.conf.RecordFormat, "", ""); err != nil {
			return
		}
	}

	pf, ok := posFiles[i.conf.PosFile]
	if !ok {
		if pf, err = NewPositionFile(i.conf.PosFile); err != nil {
			return
		}
		posFiles[i.conf.PosFile] = pf
	}
	i.pf = pf
	return
}
Exemplo n.º 2
0
func (p *OutFile) Init(env *plugin.Env) (err error) {
	p.env = env
	if err = env.ReadConfig(&p.conf); err != nil {
		return
	}
	if p.conf.Format != "" {
		p.tmpl, err = template.New("").Parse(p.conf.Format)
	}
	return
}
Exemplo n.º 3
0
func (o *StdoutOutput) Init(env *plugin.Env) (err error) {
	o.env = env
	o.conf = &Config{}
	if err = env.ReadConfig(o.conf); err != nil {
		return
	}
	if o.conf.Format != "" {
		o.tmpl, err = template.New("").Parse(o.conf.Format)
	}
	return
}
Exemplo n.º 4
0
func (p *OutPostgres) Init(env *plugin.Env) (err error) {
	p.env = env
	if err = env.ReadConfig(&p.conf); err != nil {
		return
	}
	p.pool = &sync.Pool{
		New: func() interface{} {
			return new(bytes.Buffer)
		},
	}
	p.spool = []string{"", "$1"}
	for i, l := 2, len(p.conf.Mapping); i <= l; i++ {
		p.spool = append(p.spool, fmt.Sprintf("%s,$%d", p.spool[i-1], i))
	}
	return
}
Exemplo n.º 5
0
func (o *ForwardOutput) Init(env *plugin.Env) (err error) {
	o.env = env
	o.conf = &Config{}
	if err = env.ReadConfig(o.conf); err != nil {
		return
	}
	if o.conf.MinWeight == 0 {
		o.conf.MinWeight = 5
	}
	if o.conf.Compatible == CompatibleDisable {
		mh = &codec.MsgpackHandle{RawToString: true, WriteExt: true}
	} else {
		mh = &codec.MsgpackHandle{}
	}
	o.ackEnabled = (o.conf.Compatible == CompatibleDisable && o.conf.AckTimeout > 0) ||
		o.conf.Compatible == CompatibleExtend

	var seq sequencer
	if o.ackEnabled {
		var s sequence
		seq = &s
	}

	if len(o.conf.Servers) == 0 {
		return errors.New("No server specified")
	}
	w := NewRoundRobinWriter(o.conf.MinWeight)
	for _, v := range o.conf.Servers {
		f := func(s string) ConnectFunc {
			return func() (net.Conn, error) {
				return net.DialTimeout("tcp", s, 5*time.Second)
			}
		}(v.Server)
		if v.Weight == 0 {
			v.Weight = 60
		}
		w.Add(NewAutoConnectWriter(f, seq, time.Duration(o.conf.AckTimeout)), v.Weight)
	}
	go func() {
		for err := range w.ErrorC {
			o.env.Log.Warning(err)
		}
	}()
	o.w = w
	return
}
Exemplo n.º 6
0
func (o *ElasticsearchOutput) Init(env *plugin.Env) error {
	o.env = env
	o.conf = &Config{}
	if err := env.ReadConfig(o.conf); err != nil {
		return err
	}
	if o.conf.TypeName == "" {
		o.conf.TypeName = "fluxion"
	}
	if o.conf.LogstashPrefix == "" {
		o.conf.LogstashPrefix = "logstash"
	}
	if o.conf.LogstashDateFormat == "" {
		o.conf.LogstashDateFormat = "2006.01.02"
	}
	o.client = &http.Client{Timeout: defaultTimeout}
	o.utc, _ = time.LoadLocation("")
	return nil
}
Exemplo n.º 7
0
func (f *JSFilter) Init(env *plugin.Env) (err error) {
	f.env = env
	f.conf = &Config{}
	if err = env.ReadConfig(f.conf); err != nil {
		return
	}

	if f.conf.ScriptFile != "" {
		b, err := ioutil.ReadFile(f.conf.ScriptFile)
		if err != nil {
			return err
		}
		f.conf.Script = string(b)
	}

	f.vm = otto.New()
	f.script, err = f.vm.Compile("", f.conf.Script)
	return
}
Exemplo n.º 8
0
func (i *ForwardInput) Init(env *plugin.Env) error {
	i.env = env
	i.conf = &Config{}
	return env.ReadConfig(i.conf)
}