Skip to content

Dynamic templating

Dynamic templating lets you customize notification content and routing using Tera expressions. Use it to make messages, routing rules, and connector configurations respond to alert or case data in real time.

Where you can use dynamic templating

You can use Tera expressions in:

  • connectors: dynamically set URLs, headers, channels, or service keys
  • presets: customize message content for alerts and cases
  • routing rules: create conditions that determine where notifications are sent

What dynamic templating does

Dynamic templating allows you to:

  • insert alert or case values directly into message templates
  • apply conditional logic (if, elif, else)
  • format timestamps, numbers, and text
  • route notifications based on metadata such as priority, team, or service

Global context available

All templates have access to a built-in _context variable containing metadata about the notification source.
VariableDescription
_contextContains metadata about the context of the notification source type.
_context.entityTypeThe notification source type (alerts, cases).
_context.entitySubTypeThe entity subtype (for example, metricThresholdTriggered).
_context.entityLabelsNotification source type labels associated with the context (e.g., host, region).
_context.systemInformation about the system, including its ID and name.
_context.system.idThe system's unique identifier.
_context.system.nameYour Coralogix team or system name (e.g., acme-prod).
_context.triggerThe trigger that initiated the notification source type.
_context.trigger.typeTrigger type (manual, automatic).
_context.trigger.automaticTriggerAutomatic trigger details (if applicable).
_context.trigger.manualTriggerManual trigger details (e.g., user email).
_context.trigger.manualTrigger.userEmailThe email address of the user who manually triggered the notification source type.

Common use cases

Insert dynamic values

{{ alertDef.priority }} - {{ alertDef.name }}
````
### Conditional output
```tera
{% if alertDef.priority == "P1" %}
#critical-alerts
{% elif alertDef.priority == "P3" %}
#warn-alerts
{% else %}
#general
{% endif %}

Format dates

{{ alert.timestamp | date(format="%Y-%m-%d %H:%M") }}

Use default values

{{ alertDef.entityLabels.team | default(value="no team assigned") }}

Inspect context

To view the entire context object during configuration, use:

{{ get_context() | json_encode(pretty = true) }}

Note

  • Wrap dynamic expressions in {{ }} or {% %}.
  • Use the default filter to handle missing values.
  • Keep templates simple; avoid unnecessary complexity.
  • Test templates with example data before saving.

Example: conditional alert handling based on name

{% if alertDef.name == "RDS Instance Low CPU" %}
affected db: {{ alert.groups[0].keyValues.DBInstanceIdentifier }}
credit balance is below: {{ i.condition.threshold }}
owning team: {{ alert.groups[0].keyValues.Team }}

{% elif alertDef.name == "OOM killed pod" %}
pod: {{ alert.groups[0].keyValues.k8s_pod_name }}
container: {{ alert.groups[0].keyValues.k8s_container_name }}

{% else %}
{{ alertDef.name }} is triggering
{% endif %}

Example: logs threshold alert description

{{ alert.timestamp | date(format="%Y-%m-%d %H:%M") }}

We've detected that the query result has dropped below the threshold for the following values of {{ alertDef.groupByKeys }}:

Priority / Values / Threshold / Start Time / End Time
{% for i in alert.groups %}
{{ i.priority }} / {{ i.keyValues | json_escape }} / {{ i.details.logsThreshold.fromTimestamp | date(format="%Y-%m-%d %H:%M") }} / {{ i.details.logsThreshold.toTimestamp }}
{% endfor %}

Alert Query:
{{ alertDef.typeDefinition.logsThreshold.luceneQuery }}

Alert Condition Rules:
Condition type - {{ alertDef.typeDefinition.logsThreshold.rules[0].condition.conditionType }}
Condition rules -
{% for i in alertDef.typeDefinition.logsThreshold.rules %}
Threshold: {{ i.condition.threshold }}, timeframe: {{ i.condition.timeWindow.logsTimeWindowSpecificValue }}.
{% endfor %}

@jane.doe  
@here

Example: grouping by service

{
  "alert_url": "https://teamname-prod.app.eu2.coralogix.com/#/alerts/{{ alert.id }}",
  "service": "{{ alert.groups[0].keyValues.service_name }}",
  "priority": "{{ alertDef.priority }}",
  "timestamp": "{{ alert.timestamp | date(format=\"%Y-%m-%d %H:%M\") }}",
  "status": "{{ alert.status }}"
}

Next steps

Was this helpful?