Пример #1
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
}
Пример #2
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
}
Пример #3
0
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
}
Пример #4
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")
}
Пример #5
0
func (ctx *Ctx) LoadConfig(path *string) error {
	err := cfgfile.Read(&ctx.UserConfig, *path)
	if err != nil {
		return fmt.Errorf("loading config file error: %v\n", err)
	}

	// Process top-level configuration
	// server_url
	ctx.ServerUrl, err = url.Parse(ctx.UserConfig.ServerUrl)
	if err != nil || ctx.ServerUrl.Scheme == "" || ctx.ServerUrl.Host == "" {
		log.Fatal("Server-url is not valid. Should be like http://127.0.0.1:9000/api/ ", err)
	}
	if ctx.UserConfig.ServerUrl == "" {
		log.Fatalf("Server-url is empty.")
	}

	// collector_id
	if ctx.UserConfig.CollectorId == "" {
		log.Fatal("No collector ID was configured.")
	}
	ctx.CollectorId = common.GetCollectorId(ctx.UserConfig.CollectorId)

	// node_id
	if ctx.UserConfig.NodeId == "" {
		log.Info("No node-id was configured, falling back to hostname")
		ctx.UserConfig.NodeId, err = common.GetHostname()
		if err != nil {
			log.Fatal("No node-id configured and not able to obtain hostname as alternative.")
		}
	}

	// tags
	if len(ctx.UserConfig.Tags) == 0 {
		log.Fatal("Please define configuration tags.")
	} else {
		log.Info("Fetching configurations tagged by: ", ctx.UserConfig.Tags)
	}

	// cache_path
	if ctx.UserConfig.CachePath == "" {
		var cachePath string
		if runtime.GOOS == "windows" {
			cachePath = filepath.Join(os.Getenv("SystemDrive")+"\\", "Program Files", "graylog", "collector-sidecar", "cache")
		} else {
			cachePath = filepath.Join("/var", "cache", "graylog", "collector-sidecar")
		}
		ctx.UserConfig.CachePath = cachePath
		log.Errorf("No cache directory was configured. Using default: %s", cachePath)
	}

	// log_path
	if ctx.UserConfig.LogPath == "" {
		log.Fatal("No log directory was configured.")
	}

	// log_rotation_time
	if !(ctx.UserConfig.LogRotationTime > 0) {
		log.Fatal("Please set the log rotation time > 0 seconds.")
	}

	// log_max_age
	if !(ctx.UserConfig.LogMaxAge > 0) {
		log.Fatal("Please set the maximum age of log file rotation > 0 seconds.")
	}

	// list log files
	if len(ctx.UserConfig.ListLogFiles) > 0 {
		for _, dir := range ctx.UserConfig.ListLogFiles {
			if !common.IsDir(dir) {
				log.Fatal("Please provide a list of directories for list_log_files.")
			}
		}
	}

	// update_interval
	if !(ctx.UserConfig.UpdateInterval > 0) {
		log.Fatal("Please set update interval > 0 seconds.")
	}

	// backends
	if len(ctx.UserConfig.Backends) == 0 {
		log.Fatal("Please define at least one collector backend.")
	}

	return nil
}