示例#1
0
func (l *LibratoOutlet) outlet() {
	for payloads := range l.outbox {
		if len(payloads) < 1 {
			fmt.Printf("at=%q\n", "empty-metrics-error")
			continue
		}
		//Since a playload contains all metrics for
		//a unique librato user/pass, we can extract the user/pass
		//from any one of the payloads.
		decr, err := auth.Decrypt(payloads[0].Auth)
		if err != nil {
			fmt.Printf("error=%s\n", err)
			continue
		}
		creds := strings.Split(decr, ":")
		if len(creds) != 2 {
			fmt.Printf("error=missing-creds\n")
			continue
		}
		libratoReq := &libratoRequest{payloads}
		j, err := json.Marshal(libratoReq)
		if err != nil {
			fmt.Printf("at=json error=%s user=%s\n", err, creds[0])
			continue
		}
		if err := l.postWithRetry(creds[0], creds[1], j); err != nil {
			l.Mchan.Measure("outlet.drop", 1)
		}
	}
}
示例#2
0
func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	atomic.AddUint64(&r.numReqs, 1)
	defer r.Mchan.Time("http.accept", time.Now())
	if req.Method != "POST" {
		fmt.Printf("error=%q\n", "Non post method received.")
		http.Error(w, "Invalid Request", 400)
		return
	}
	// If we can decrypt the authentication
	// we know it is valid and thus good enought
	// for our receiver. Later, another routine
	// can extract the username and password from
	// the auth to use it against the Librato API.
	authLine, ok := req.Header["Authorization"]
	if !ok && len(authLine) > 0 {
		fmt.Printf("error=%q\n", "Missing authorization header.")
		http.Error(w, "Missing Auth.", 400)
		return
	}
	parseRes, err := auth.Parse(authLine[0])
	if err != nil {
		fmt.Printf("error=%s\n", err)
		http.Error(w, "Fail: Parse auth.", 400)
		return
	}
	var creds string
	if creds, err = auth.Decrypt(parseRes); err != nil {
		fmt.Printf("error=%s\n", err)
		http.Error(w, "Invalid Request", 400)
		return
	}
	defer r.Mchan.CountReq(strings.Split(creds, ":")[0])
	v := req.URL.Query()
	v.Add("auth", parseRes)
	b, err := ioutil.ReadAll(req.Body)
	req.Body.Close()
	if err != nil {
		fmt.Printf("error=%q\n", "Unable to read request body.")
		http.Error(w, "Invalid Request", 400)
		return
	}
	r.Receive(b, v)
}
示例#3
0
func (p *parser) handleHkLogplexErr() bool {
	if string(p.lr.Header().Procid) != logplexPrefix {
		return false
	}
	matches := bucketDropExpr.FindStringSubmatch(string(p.lr.Bytes()))
	if len(matches) < 2 {
		return false
	}
	numDrops, err := strconv.Atoi(matches[1])
	if err != nil {
		return false
	}
	if decr, err := auth.Decrypt(p.Auth()); err == nil {
		user := strings.Split(decr, ":")[0]
		fmt.Printf("error=logplex.l10 drops=%d user=%s\n", numDrops, user)
	}
	p.mchan.Measure("logplex.l10", float64(numDrops))
	return true
}