Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

number variables from alert are typed string and cannot be used in templates with lt/gt/eq ? #1759

Closed
Dieterbe opened this issue May 27, 2016 · 2 comments

Comments

@Dieterbe
Copy link
Contributor

Dieterbe commented May 27, 2016

IIRC I spoke about this with Matt Jibson years ago, and although I couldn't find the ticket, I think it has always been an unresolved issue

basically when you have something like this in your template {{else if lt $v.Value $.Alert.Vars.b }} you're bound to get error calling lt: incompatible types for comparison
no matter whether you define $b as 60 or 60.0, v.Value is a number obtained from streak(), printf says the type is expr.Number, whereas $b has type string.

notably if you replace $.Alert.Vars.b with 60.0 it works fine

@Dieterbe Dieterbe changed the title cannot use variables with lt/gt/eq ? number variables from alert are typed string and cannot be used in templates with lt/gt/eq ? May 27, 2016
@kylebrandt
Copy link
Member

I think you need to wrap $b in Eval:

template test {
    subject = {{.Last.Status}}: {{.Alert.Name}} on {{.Group.host}}
    body = `{{ lt (.Eval .Alert.Vars.q) (.Eval .Alert.Vars.threshold) }}`
}

alert test {
    template = test
    $q = avg(q("avg:rate:os.cpu{host=*bosun*}", "5m", ""))
    $threshold = 1
    crit = avg(q("avg:rate:os.cpu{host=*bosun*}", "5m", "")) > $threshold
}

@Dieterbe
Copy link
Contributor Author

you're right! that makes it work, and it doesn't even matter if declared as 60 or 60.0
both work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants