func (r *ExecRunner) run() {
	log.Infof("[%s] Starting (%s driver)", r.name, r.backend.Driver())

	if r.stderr != "" {
		err := common.CreatePathToFile(r.stderr)
		if err != nil {
			backends.SetStatusLogErrorf(r.name, "Failed to create path to collector's stderr log: %s", r.stderr)
		}

		f := common.GetRotatedLog(r.stderr, r.context.UserConfig.LogRotationTime, r.context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stderr = f
	}
	if r.stdout != "" {
		err := common.CreatePathToFile(r.stdout)
		if err != nil {
			backends.SetStatusLogErrorf(r.name, "Failed to create path to collector's stdout log: %s", r.stdout)
		}

		f := common.GetRotatedLog(r.stderr, r.context.UserConfig.LogRotationTime, r.context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stdout = f
	}

	r.backend.SetStatus(backends.StatusRunning, "Running")
	err := r.cmd.Start()
	if err != nil {
		backends.SetStatusLogErrorf(r.name, "Failed to start collector: %s", err)
	}
}
Beispiel #2
0
func (wlbc *WinLogBeatConfig) RenderToFile() error {
	stringConfig := wlbc.Render()
	err := common.CreatePathToFile(wlbc.Beats.UserConfig.ConfigurationPath)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(wlbc.Beats.UserConfig.ConfigurationPath, stringConfig.Bytes(), 0644)
	return err
}
Beispiel #3
0
func (nxc *NxConfig) RenderToFile() error {
	stringConfig := nxc.Render()
	err := common.CreatePathToFile(nxc.UserConfig.ConfigurationPath)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(nxc.UserConfig.ConfigurationPath, stringConfig, 0644)
	return err
}
Beispiel #4
0
func (nxc *NxConfig) ValidatePreconditions() bool {
	if runtime.GOOS == "linux" {
		if !common.IsDir("/var/run/graylog/collector-sidecar") {
			err := common.CreatePathToFile("/var/run/graylog/collector-sidecar/nxlog.run")
			if err != nil {
				return false
			}
		}
	}
	return true
}
Beispiel #5
0
func (nxc *NxConfig) ConfigurationPath() string {
	configurationPath := nxc.UserConfig.ConfigurationPath
	if !common.IsDir(filepath.Dir(configurationPath)) {
		err := common.CreatePathToFile(configurationPath)
		if err != nil {
			log.Fatalf("[%s] Configured path to collector configuration does not exist: %s", nxc.Name(), configurationPath)
		}
	}

	return configurationPath
}
func (fbc *FileBeatConfig) ConfigurationPath() string {
	configurationPath := fbc.Beats.UserConfig.ConfigurationPath
	if !common.IsDir(filepath.Dir(configurationPath)) {
		err := common.CreatePathToFile(configurationPath)
		if err != nil {
			log.Fatal("Configured path to collector configuration does not exist: " + configurationPath)
		}
	}

	return configurationPath
}
Beispiel #7
0
func (fbc *FileBeatConfig) CachePath() string {
	cachePath := fbc.Beats.Context.UserConfig.CachePath
	if !common.IsDir(filepath.Dir(cachePath)) {
		err := common.CreatePathToFile(cachePath)
		if err != nil {
			log.Fatal("Configured path to cache directory does not exist: " + cachePath)
		}
	}

	return filepath.Join(cachePath, "filebeat", "data")
}
Beispiel #8
0
func (r *Runner) run() {
	log.Infof("[%s] Starting", r.Name)

	if r.Stderr != "" {
		err := common.CreatePathToFile(r.Stderr)
		if err != nil {
			msg := "Failed to create path to collector's stderr log"
			r.Backend.SetStatus(backends.StatusError, msg)
			log.Errorf("[%s] %s: %s", r.Name, msg, r.Stderr)
		}

		f := common.GetRotatedLog(r.Stderr, r.Context.UserConfig.LogRotationTime, r.Context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stderr = f
	}
	if r.Stdout != "" {
		err := common.CreatePathToFile(r.Stdout)
		if err != nil {
			msg := "Failed to create path to collector's stdout log"
			r.Backend.SetStatus(backends.StatusError, msg)
			log.Errorf("[%s] %s: %s", r.Name, msg, r.Stdout)
		}

		f := common.GetRotatedLog(r.Stderr, r.Context.UserConfig.LogRotationTime, r.Context.UserConfig.LogMaxAge)
		defer f.Close()
		r.cmd.Stdout = f
	}

	r.Running = true
	r.Backend.SetStatus(backends.StatusRunning, "Running")
	startTime := time.Now()
	r.cmd.Run()

	if time.Since(startTime) < 3*time.Second {
		msg := "Collector exits immediately, this should not happen! Please check your collector configuration!"
		r.Backend.SetStatus(backends.StatusError, msg)
		log.Errorf("[%s] %s", r.Name, msg)
	}

	return
}