Example #1
0
File: alert.go Project: enova/tokyo
// Set configures the alert settings
func Set(cfg *cfg.Config) {

	// Configure: Sentry-Client
	if cfg.Has("Alert.Sentry.Use") {

		// Use
		use := cfg.Get("Alert.Sentry.Use")
		if use == "true" || use == "True" {
			sentryCfg := cfg.Descend("Alert.Sentry")
			setSentry(sentryCfg)
		}
	}

	// Configure: Log-File
	if cfg.Has("Alert.LogFile.Use") {

		// Use
		use := cfg.Get("Alert.LogFile.Use")
		if use == "true" || use == "True" {
			logFileCfg := cfg.Descend("Alert.LogFile")
			setLogFile(logFileCfg)
		}
	}
}
Example #2
0
File: alert.go Project: enova/tokyo
// Configure Sentry
func setSentry(cfg *cfg.Config) {
	var err error

	// URL (From Env)
	url := os.Getenv("SENTRY_DSN")

	// Overwrite With Config URL
	if cfg.Has("DSN") {
		url = cfg.Get("DSN")
	}

	// Tags
	tags := make(map[string]string)
	tags["user"] = username()
	tags["app"] = os.Args[0]
	tags["cmd"] = strings.Join(os.Args, " ")
	tags["pid"] = fmt.Sprintf("%d", os.Getpid())

	// Custom-Tags
	for t := 0; t < cfg.Size("Tag"); t++ {
		line := cfg.GetN(t, "Tag")
		tokens := strings.Fields(line)

		// Invalid Tag
		if len(tokens) < 2 {
			Cerr("Tag should have at least two tokens - key value..., " + line)
			continue
		}

		// Add Tag
		key := tokens[0]
		val := strings.Join(tokens[1:], " ")
		tags[key] = val
	}

	// Create Sentry-Client
	sentry, err = raven.NewWithTags(url, tags)
	if err != nil {
		log.Fatal(err)
	}

	Cerr("Sentry: " + tagsToS(tags))
}