influxdata / influxdata/kapacitor
Enhancement: Exposing TICK Vars to Alert template expansion
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
Currently there is no way to access TICK variable from within a alert template, so pre expansion needs to be done. As an example the following will not work as 'host_count_warn' and 'host_count_critical' are not present in the template expansion variable scope.
```
var host_count_warn = 2
var host_count_critical = 1
.... Stuff ....
|alert()
.message('Healty Host Count {{ .TaskName }} is {{ .Level }}: Got a value of {{ index .Fields "_host_count" }} expecting > {{ if .Level eq "WARN" }} {{ .host_count_warn }} {{ else }} {{ .host_count_critical }} {{ end }}')
```
The current solution is to pre-expanded using the "string" function the variable before the template is executed, i.e.
```
'{{ if eq .Level "WARN" }} ' + string(host_count_warn) + '{{ else }}' + string(host_count_critical) + '{{ end }}'
```
It would be nice and much cleaner if we could simply access the variables from a tickscript directly in the alert message as part of the template expansion.
I would propose a new map "TaskVars" or "TickTaskVars" etc that will be populated with the tick script variables, and referenced as such:
```
Healthy Host Count {{.TaskName}} is {{ .Level }}: Got a value of {{ index .Fields "_host_count" }} expecting > {{ if eq .Level "WARN" }} {{ index .TaskVars "host_count_warn"}} {{ else }} {{ index TaskVars "host_count_critical"}} {{ end }}
```
Contributor guide
Assessment
This issue has not been assessed yet.