コード例 #1
0
ファイル: outputelastic.go プロジェクト: vaderyang/gogstash
func init() {
	config.RegistOutputHandler(ModuleName, func(mapraw map[string]interface{}) (retconf config.TypeOutputConfig, err error) {
		conf := DefaultOutputConfig()
		if err = config.ReflectConfig(mapraw, &conf); err != nil {
			return
		}

		// elastic
		elasticurl, err := url.Parse(conf.URL)
		if err != nil {
			err = errutil.New("parse elastic url failed", err)
			return
		}

		conf.conn = elastigo.NewConn()
		conf.conn.Protocol = elasticurl.Scheme
		conf.conn.Domain = strings.Split(elasticurl.Host, ":")[0]
		conf.conn.Port = strings.Split(elasticurl.Host, ":")[1]
		if _, err = conf.conn.Health(); err != nil {
			err = errutil.New("test elastic connection failed", err)
			return
		}

		retconf = &conf
		return
	})
}
コード例 #2
0
func init() {
	config.RegistInputHandler(ModuleName, func(mapraw map[string]interface{}) (retconf config.TypeInputConfig, err error) {
		conf := DefaultInputConfig()
		if err = config.ReflectConfig(mapraw, &conf); err != nil {
			return
		}

		for _, pattern := range conf.IncludePatterns {
			conf.includes = append(conf.includes, regexp.MustCompile(pattern))
		}
		for _, pattern := range conf.ExcludePatterns {
			conf.excludes = append(conf.excludes, regexp.MustCompile(pattern))
		}
		if conf.hostname, err = os.Hostname(); err != nil {
			err = errutil.New("get hostname failed", err)
			return
		}
		if conf.client, err = docker.NewClient(conf.Host); err != nil {
			err = errutil.New("create docker client failed", err)
			return
		}

		retconf = &conf
		return
	})
}