influxdata / influxdata/kapacitor

Using variables within templates {{if}} {{else if}} blocks - Is this possible?

Open
#2,283 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

I don't know if this is a feature request, bug or just my lack of understanding (it could quite well be the latter) but i have run into an issue when using Kapacitor templates.

I've defined templates that are working fine however i need to change the message and include a value from a variable depending on the alert level.

I've tried to use the following as my message, the warn and crit variables are set in the script.
`var message = '{{index .Tags "cluster_uuid"}} Nutanix Alert: Total Storage Capacity is below the {{ .Level }} threshold Of {{if eq .Level "WARNING"}} ' + warn + '{{else if eq .Level "CRITICAL"}} ' + crit + ' Tb.'`

What happens:
I get this error message:
```
invalid TICKscript: Failed to handle left node: Failed to handle right node: Failed to handle 1 argument: Failed to handle node: Given node type is not valid evaluation node:
```

What i expect:
when the alert is generated, the level is evaluated, using the templates {{if}} {{else}} logic the right variable is added to the message showing the numerical value.

I've updated the message to use string(variable) which had the same issue. Is this possible to do? If not possible at the moment, how do I submit this as a feature request? It seems like something that would be useful.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the TICKscript template expression shown in the issue, including the {{if}} and {{else if}} branches and the warn and crit variables. Trace how Kapacitor parses and evaluates this template, then determine whether the expected alert message can be produced and how it should be tested.

Written by the indexing model from the issue text.

Assessment

Domain
observability-sre
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.