Example #1
0
// EnvironmentSpecificConfig sets the configuration to match the given env.
func EnvironmentSpecificConfig(v *viper.Viper, env string) *viper.Viper {
	if v == nil {
		v = viper.New()
		v.SetDefault("env", env)
	}
	// Read common config
	v.AddConfigPath(".")
	v.AddConfigPath("../")
	v.AddConfigPath("config/")
	v.AddConfigPath("../config/")
	v.SetConfigName("config-common")
	v.SetConfigType("yml")
	if err := v.ReadInConfig(); err != nil {
		panic(fmt.Errorf("Fatal error reading common config file: %s \n", err))
	}

	// Merge in environment specific config
	mergeInConfig(v, "config-"+env+".yml", "yml")
	// Merge in version config
	mergeInConfig(v, "version.properties", "properties")

	// Read config from consul
	// v.AddRemoteProvider("consul", "http://someconsul/endpoint", "some/path/to/config.json")
	// v.SetConfigType("yaml")
	// err = v.ReadRemoteConfig() // Find and read the config file
	// if err != nil {            // Handle errors reading the config file
	// 	panic(fmt.Errorf("Fatal error reading remote config file: %s \n", err))
	// }
	return v
}
Example #2
0
func AddDefaults(c *viper.Viper) {
	c.SetDefault("marathon", kv("host", "http://localhost:8080"))
	c.SetDefault("mesos", kv("master", "localhost:5050"))
	c.SetDefault("zk", kv("host", "localhost:2181"))

	cachePath, _ := homedir.Expand("~/.marathonctl/packages")
	c.SetDefault("package-cache-path", cachePath)
	c.SetDefault("package-repo", "github.com/ashwanthkumar/marathonctl-universe")
}
Example #3
0
// SetEnvironmentSpecificConfig sets the configuration to match the given env.
func SetEnvironmentSpecificConfig(v *viper.Viper, env string) {
	if v == nil {
		v = viper.New()
		v.SetDefault("env", env)
	}
	// Read common config
	v.AddConfigPath(".")
	v.AddConfigPath("../")
	v.SetConfigName("config-common")
	if err := v.ReadInConfig(); err != nil {
		panic(fmt.Errorf("Fatal error reading common config file: %s \n", err))
	}

	// Merge in environment specific config
	configName := "config-" + env + ".yml"
	configPaths := []string{configName, "../" + configName}
	configFilePath := ""
	for _, path := range configPaths {
		if b, _ := exists(path); b {
			configFilePath = path
			continue
		}
	}
	if configFilePath == "" {
		panic(fmt.Errorf("Could not find config file: %s \n", configName))
	}
	configBytes, err := ioutil.ReadFile(configFilePath)
	if err != nil {
		panic(fmt.Errorf("Could not read config file: %s \n", err))
	}
	err = v.MergeConfig(bytes.NewBuffer(configBytes)) // Find and read the config file
	if err != nil {                                   // Handle errors reading the config file
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	// Read config from consul
	v.AddRemoteProvider("consul", v.GetString("ConsulEndpoint"), v.GetString("ConsulSupportOptimizationWorkflowConfig"))
	v.SetConfigType("yaml")
	// err = v.ReadRemoteConfig() // Find and read the config file
	// if err != nil {            // Handle errors reading the config file
	// 	panic(fmt.Errorf("Fatal error reading remote config file: %s \n", err))
	// }
	Viper = &config{v}
}
Example #4
-1
func loadConfig(v *viper.Viper) *runnerConf {
	v.SetDefault("check_timeout", 10)
	v.SetDefault("host_window", 60)
	v.SetDefault("host_threshold", 5)
	v.SetDefault("flood_window", 120)
	v.SetDefault("flood_threshold", 100)
	v.SetDefault("flap_window", 1200)
	v.SetDefault("flap_threshold", 5)
	v.SetDefault("alert_threshold", 3)
	v.SetDefault("worker_id", "worker1")
	v.SetDefault("check_key", "canhazstatus")
	conf := &runnerConf{}
	conf.checkTimeout = v.GetDuration("check_timeout")
	conf.hostWindow = int64(v.GetInt("host_window"))
	conf.hostThreshold = v.GetInt("host_threshold")
	conf.floodWindow = int64(v.GetInt("flood_window"))
	conf.floodThreshold = v.GetInt("flood_threshold")
	conf.flapWindow = v.GetInt("flap_window")
	conf.flapThreshold = v.GetInt("flap_threshold")
	conf.alertThreshold = v.GetInt("alert_threshold")
	conf.workerQueue = v.GetString("worker_id")
	conf.checkKey = v.GetString("check_key")

	//twilio config
	v.SetDefault("twilio_enable", false)
	conf.twilioEnabled = v.GetBool("twilio_enable")
	conf.twsid = v.GetString("twiliosid")
	conf.twtoken = v.GetString("twiliotoken")
	conf.twfrom = v.GetString("twiliofrom")
	conf.twdest = v.GetStringSlice("twiliodest")

	//pagerduty config
	v.SetDefault("pagerduty_enable", false)
	conf.pagerDutyEnabled = v.GetBool("pagerduty_enable")
	conf.pagerDutyPriOneKey = v.GetString("pagerduty_priority_one_key")
	conf.pagerDutyPriTwoKey = v.GetString("pagerduty_priority_two_key")
	conf.pagerDutyIncidentKeyPrefix = v.GetString("pagerduty_incident_key_prefix")

	return conf
}