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.
| Variable | Description |
|---|---|
_context | Contains metadata about the context of the notification source type. |
_context.entityType | The notification source type (alerts, cases). |
_context.entitySubType | The entity subtype (for example, metricThresholdTriggered). |
_context.entityLabels | Notification source type labels associated with the context (e.g., host, region). |
_context.system | Information about the system, including its ID and name. |
_context.system.id | The system's unique identifier. |
_context.system.name | Your Coralogix team or system name (e.g., acme-prod). |
_context.trigger | The trigger that initiated the notification source type. |
_context.trigger.type | Trigger type (manual, automatic). |
_context.trigger.automaticTrigger | Automatic trigger details (if applicable). |
_context.trigger.manualTrigger | Manual trigger details (e.g., user email). |
_context.trigger.manualTrigger.userEmail | The 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
Use default values
Inspect context
To view the entire context object during configuration, use:
Note
- Wrap dynamic expressions in
{{ }}or{% %}. - Use the
defaultfilter 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
- Tera syntax reference: Explore operators, filters, and tests
- Routing rules: Use dynamic conditions to control routing behavior
- Preset configuration: Shape notification content per alert or case
Theme
Light