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 }}
@nathanielc Any updadate :)
If you're going to extend this for the message property, then extending for id and log would be ideal too.
May be it is assumption that with flux this is not getting probably a priority but this is super important or us as we need to send alerts in a format which servicenow itom can accept and therefore must be able to customize HTTP post bodies.
Wwe should be able to send something like this
Expected
Must be able to access .Tags outside .Message
{
"id": "{{.ID}}",
"message": "{{.Message}}",
"node": "{{index .Tags "host"}}", ---------> Currently I cannot access .Tags outside .Message
"details": "{{.Details}}",
"time": "{{.Time}}",
"duration": "{{ .Duration}}",
"level": "{{.Level}}",
"recoverable": {{.Recoverable}},
"data": {{ .Data }}
"hardcoded": "test"
}
We should also be able to translate .Level to an integer value
Example:
Critical = 5
Warning = 4
Info = 3
Most helpful comment
@nathanielc Any updadate :)