Skip to main content

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​

TypeExampleDescription
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​

OperatorExampleDescription
==alert.highestPriority == "P1"Equal to
!=alert.status != "Resolved"Not equal
> , < , >= , <=alert.value > 80Greater/less comparisons

Logical operators​

OperatorExampleDescription
andalert.highestPriority == "P1" and alert.status == "Triggered"Both must be true
oralert.highestPriority == "P1" or alertDef.priority == "P2"Either can be true
notnot alert.status == "Resolved"Negates a condition

String tests​

FunctionExampleResult
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 (|).

FilterExample
default{{ alert.highestPriority | 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.

ExampleDescription
alert.highestPriority == "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
trueAlways 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​

Build, validate, and troubleshoot Tera templates in Tera usage and troubleshooting.

Last updated on