Esempio n. 1
0
func updateRuntimeConfiguration(respBody *graylog.ResponseCollectorRegistration, ctx *context.Ctx) error {
	// API query interval
	if ctx.UserConfig.UpdateInterval != respBody.Configuration.UpdateInterval &&
		respBody.Configuration.UpdateInterval > 0 &&
		respBody.ConfigurationOverride == true {
		log.Infof("[ConfigurationUpdate] update_interval: %ds", respBody.Configuration.UpdateInterval)
		ctx.UserConfig.UpdateInterval = respBody.Configuration.UpdateInterval
		configurationOverride = true
	}
	// Send host status
	if ctx.UserConfig.SendStatus != respBody.Configuration.SendStatus &&
		respBody.ConfigurationOverride == true {
		log.Infof("[ConfigurationUpdate] send_status: %v", respBody.Configuration.SendStatus)
		ctx.UserConfig.SendStatus = respBody.Configuration.SendStatus
		configurationOverride = true
	}
	// Reset server overrides
	if respBody.ConfigurationOverride == false && configurationOverride == true {
		configFile := cfgfile.SidecarConfig{}
		err := cfgfile.Read(&configFile, "")
		if err != nil {
			log.Errorf("[ConfigurationUpdate] Failed to load default values from configuration file. Continuing with current values. %v", err)
			return err
		} else {
			log.Infof("[ConfigurationUpdate] Resetting update_interval: %ds", configFile.UpdateInterval)
			ctx.UserConfig.UpdateInterval = configFile.UpdateInterval
			log.Infof("[ConfigurationUpdate] Resetting send_status: %v", configFile.SendStatus)
			ctx.UserConfig.SendStatus = configFile.SendStatus
			configurationOverride = false
		}
	}
	return nil
}
Esempio n. 2
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
}
Esempio n. 3
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:12900 ", 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)
	}

	// 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.")
	}

	// 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
}