Kapacitor: configure alert messages for the deadman function

What we want to achieve is to configure the message template that is used by the deadman function. The message that should be displayed should depend on the value of .Level. Two variables are created (start_summary and end_summary and message) and depending on the value of .Level either the value of start_summary or the end_summary variable should be outputted by deadman. Normally, these vars are declared vars and get their value from a JSON variable file.
Below is the template (relevant part).

The vars start_summary and end_summary are added as Tags using the DefaultNode. These vars themselves include a Tag. Depending on the value of .Level the correct message is displayed, however, the Tag in the vars is not replaced. For instance the following message is displayed:

[PROBLEM] The data measurements are missing for runtime {{ index .Tags “runtime-name” }} [Testing]

Is it somehow possible to get the Tag that is referenced by the vars start_summary and end_summary evaluated and replaced by the actual name of the runtime?
This runtime does exist as a Tag by the way.

var start_summary = ‘[PROBLEM] The data measurements are missing for runtime {{ index .Tags “runtime-name” }} [Testing]’
var end_summary = ‘[FIXED] The data measurements are missing for runtime {{ index .Tags “runtime-name” }} [Testing]’

Template:

var message = ‘{{ if eq .Level “CRITICAL” }} {{index .Tags “start_summary”}} {{ else if eq .Level “OK” }} {{index .Tags “end_summary”}} {{ end }}’

var dayRestriction lambda
var timeRestriction lambda

var qry = ‘SELECT count(*) FROM "’ + db + ‘"."’ + rp + ‘"."’ + measurement + '" WHERE ’ + whereClause

var data = batch
|query(qry)
.period(period)
.cron(qryCronExpr)
.groupBy(‘environment’, ‘runtime-name’)
|default().tag(‘start_summary’, start_summary)
|default().tag(‘end_summary’, end_summary)

var trigger = data
|deadman(threshold, interval, lambda: dayRestriction AND timeRestriction)
.message(message)
.stateChangesOnly()
.details(’’)
.post(‘http://…’)

Hello @FrankL,
Welcome and thanks for your question. I’m having trouble understanding your problem. Can you describe what your higher-level problem is? Also, can you please help me by providing a simple example of what you’re trying to achieve/expect and what your script is actually returning?

Hello Anaisdg,

I have a batch node combined with a query node that uses a groupBy. This groupBy groups on runtime-name, so the runtime-name appears in the Tag map. Further, I have two string variables that reference that runtime-name Tag. These are the variables:

var start_summary = ‘[PROBLEM] Start summary text for runtime {{ index .Tags “runtime-name” }}’

var end_summary = ‘[FIXED] End summary text for runtime {{ index .Tags “runtime-name” }}’

I added these variables to the Tag map by using the DefaultNode so I can reference them via a Golang template via the construction with the curly braces.

Then, following the batch node is the deadman function. For the deadman function I use the following message (this message refers to the Tags that were created for the variables):

var message = ‘{{ if eq .Level “CRITICAL” }} {{index .Tags “start_summary”}} {{ else if eq .Level “OK” }} {{index .Tags “end_summary”}} {{ end }}’

The deadman function is used to detect if during a certain period data were missing. If for a certain amount of time there was no data, and Level gets the value CRITICAL, I want to see the value of variable start_summary, and when the value of Level changes to OK again, I want to see the value of the variable end_summary.
Lets assume that the name of the involved runtime is ‘system.container’.

When Level gets the value CRITICAL, I want to see:

[PROBLEM] Start summary text for runtime system.container

But what I see is:

[PROBLEM] Start summary text for runtime {{ index .Tags “runtime-name” }}

The runtime-Tag in the curly braces doesn’t get evaluated. The same happens when Level goes from CRITICAL to OK again. Then, I want to see the message:

[FIXED] End summary text for runtime system.container

I get:

[FIXED] End summary text for runtime {{ index .Tags “runtime-name” }}

Is it possible to let the deadman function output a message, depending on values of alert data where the messages are in the Tag map and where the messages themselves reference a Tag? Is it possible to fix that the Tag in those messages gets evaluated? Or is a different approach is needed for letting messages depend on values of alert data? What are the possibilities?