Tera syntax quick reference
Use this guide to build and troubleshoot Tera expressions in Notification Center. Tera syntax powers dynamic templating for connectors, presets, and routing rules.
Basic syntax
| Type | Example | Description |
|---|---|---|
| Variable | {{ alertDef.name }} | Displays the value of a variable. |
| Conditional | {% if alert.status == "Triggered" %}...{% endif %} | Adds logic to control output. |
| Loop | {% for i in alert.groups %}{{ i.priority }}{% endfor %} | Iterates through a list. |
Comparison operators
| Operator | Example | Description |
|---|---|---|
== | alertDef.priority == "P1" | Equal to |
!= | alert.status != "Resolved" | Not equal |
> , < , >= , <= | alert.value > 80 | Greater/less comparisons |
Logical operators
| Operator | Example | Description |
|---|---|---|
and | alertDef.priority == "P1" and alert.status == "Triggered" | Both must be true |
or | alertDef.priority == "P1" or alertDef.priority == "P2" | Either can be true |
not | not alert.status == "Resolved" | Negates a condition |
String tests
| Function | Example | Result |
|---|---|---|
is starting_with() | alertDef.name is starting_with("CPU") | true if the name begins with CPU |
is containing() | alertDef.description is containing("latency") | true if the text includes the word |
is matching() | alertDef.name is matching("(?i)^cpu") | Regex match |
Filters
Filters transform or format values. Apply them with a pipe (|).
| Filter | Example |
|---|---|
default | {{ alertDef.priority | default(value="P3") }} |
date | {{ alert.timestamp | date(format="%Y-%m-%d %H:%M") }} |
json_encode | {{ get_context() | json_encode(pretty=true) }} |
json_escape | {{ alert.groups | json_escape }} |
lower | {{ alertDef.name | lower }} |
replace | {{ alertDef.name | replace(from=" ", to="_") }} |
Boolean conditions in routing rules
Routing rule conditions must evaluate to true or false.
Do not wrap conditions in {{ }}—enter only the expression.
| Example | Description |
|---|---|
alertDef.priority == "P1" | Routes only P1 alerts |
alertDef.name is containing("CPU") | Routes alerts with “CPU” in the name |
alertDef.entityLabels.environment == "prod" | Routes based on environment |
true | Always triggers |
Note
- Use
{{ get_context() | json_encode(pretty=true) }}to print all available variables. - Wrap optional values with
default()to avoid errors. - Missing variables cause expressions to evaluate to
false. - Keep expressions readable—avoid complex logic in message fields.
Next steps
- Dynamic Templating: Learn how Tera expressions apply across connectors, presets, and routing rules
- Routing Rules: Use boolean conditions and string tests in routing expressions
- Preset Setup for Alerts Embed Tera expressions into alert-specific message templates
Theme
Light