Kapacitor template tasks and script variables

Hi,

I’ve asked this before but got no response. Hopefully someone on here might respond this time :slight_smile:

I’m working with Kapacitor templates and need to pass a variable in to the message that is generated when an alert is created. This variable is the threshold value so i would end up with a message like “hostname is over the threshold of <threshold_value> with <current_value>”

If i try to create a template task with this line
var message = '{{index .Tags "esxhostname"}} - {{ index .Tags "vmname" }} VMware Memory Usage is over the threshold of ' + threshold + ' with a value of {{ index .Fields "usage_average" | printf "%0.2f"}}% Usage.'

I get the following error
Kapacitor: invalid TICKscript: Failed to handle left node: Failed to handle right node: Failed to handle node: Given node type is not valid evaluation node:

If i remove the the ' + threshold + ' section and try to define the alert it works perfectly.

Why doesn’t this work in the template? Can provide full script if wanted.

Phil

so nothing, no one? fantastic

Annoyingly, this line works

var idVar = name + ':{{index .Tags "host_name"}}-{{index .Tags "vm_name"}}' + priority

but this line does not

var message = '{{index .Tags "host_name"}} Alert: CPU Consumption Over {{index .Fields "cpu_used"}}. Above the threshold of' + condition

They are both empty variables in the template until I actually create an alert. Why does one work and not the other?