作者:jm
项目:bosu
// Expr takes an expression in the form of a string, changes the tags to
// match the context of the alert, and returns a link to the expression page.
func (c *Context) Expr(v string) string {
p := url.Values{}
p.Add("date", c.runHistory.Start.Format(`2006-01-02`))
p.Add("time", c.runHistory.Start.Format(`15:04`))
p.Add("expr", base64.StdEncoding.EncodeToString([]byte(opentsdb.ReplaceTags(v, c.Group))))
return c.schedule.Conf.MakeLink("/expr", &p)
}
作者:jm
项目:bosu
func (c *Context) evalExpr(e *expr.Expr, filter bool, series bool, autods int) (expr.ResultSlice, string, error) {
var err error
if filter {
e, err = expr.New(opentsdb.ReplaceTags(e.Text, c.State.Group), c.schedule.Conf.Funcs())
if err != nil {
return nil, "", err
}
}
if series && e.Root.Return() != parse.TypeSeriesSet {
return nil, "", fmt.Errorf("need a series, got %T (%v)", e, e)
}
res, _, err := e.Execute(c.runHistory.Context, c.runHistory.GraphiteContext, c.runHistory.Logstash, c.runHistory.Cache, nil, c.runHistory.Start, autods, c.Alert.UnjoinedOK, c.schedule.Search, c.schedule.Conf.AlertSquelched(c.Alert), c.runHistory)
if err != nil {
return nil, "", fmt.Errorf("%s: %v", e, err)
}
return res.Results, e.String(), nil
}
作者:mhenderson-s
项目:bosu
func (c *Context) evalExpr(e *expr.Expr, filter bool, series bool, autods int) (expr.ResultSlice, string, error) {
var err error
if filter {
e, err = expr.New(opentsdb.ReplaceTags(e.Text, c.AlertKey.Group()), c.schedule.RuleConf.GetFuncs(c.schedule.SystemConf.EnabledBackends()))
if err != nil {
return nil, "", err
}
}
if series && e.Root.Return() != models.TypeSeriesSet {
return nil, "", fmt.Errorf("need a series, got %T (%v)", e, e)
}
providers := &expr.BosunProviders{
Cache: c.runHistory.Cache,
Search: c.schedule.Search,
Squelched: c.schedule.RuleConf.AlertSquelched(c.Alert),
History: c.schedule,
}
res, _, err := e.Execute(c.runHistory.Backends, providers, nil, c.runHistory.Start, autods, c.Alert.UnjoinedOK)
if err != nil {
return nil, "", fmt.Errorf("%s: %v", e, err)
}
return res.Results, e.String(), nil
}
作者:marswan
项目:bosu
func (e *State) AddComputation(r *Result, text string, value interface{}) {
if !e.enableComputations {
return
}
r.Computations = append(r.Computations, Computation{opentsdb.ReplaceTags(text, r.Group), value})
}