Пример #1
0
func (s *Service) Create(
	name string,
	l *log.Logger,
	abortCallback func(),
) (udf.Interface, error) {
	conf, ok := s.configs[name]
	if !ok {
		return nil, fmt.Errorf("no such UDF %s", name)
	}
	if conf.Socket != "" {
		// Create socket UDF
		return kapacitor.NewUDFSocket(
			kapacitor.NewSocketConn(conf.Socket),
			l,
			time.Duration(conf.Timeout),
			abortCallback,
		), nil
	} else {
		// Create process UDF
		env := os.Environ()
		for k, v := range conf.Env {
			env = append(env, fmt.Sprintf("%s=%s", k, v))
		}
		commander := kapacitor.CommandInfo{
			Prog: conf.Prog,
			Args: conf.Args,
			Env:  env,
		}
		return kapacitor.NewUDFProcess(
			commander,
			l,
			time.Duration(conf.Timeout),
			abortCallback,
		), nil
	}
}
Пример #2
0
func newUDFSocket(name string) (*kapacitor.UDFSocket, *udf_test.IO) {
	uio := udf_test.NewIO()
	l := log.New(os.Stderr, fmt.Sprintf("[%s] ", name), log.LstdFlags)
	u := kapacitor.NewUDFSocket(newTestSocket(uio), l, 0, nil)
	return u, uio
}