Advanced configuration
Templating for dynamic routing
The Channel and Service key fields support Tera templating, enabling dynamic routing by inserting variables into the notification configuration. This allows notifications to be sent to different channels within Slack based on alert attributes.
Customization examples:
Using alert priority
This configuration dynamically inserts the priority of an alert into the channel name.
The
{{alert.highestPriority}}placeholder retrieves the priority level from the alert (alert).The notification is sent to a channel with the format
priority-interface(for example,high-interface,medium-interface).
Routing based on the first group's team ID
This configuration dynamically routes notifications based on the team ID found in the first alert group.
The placeholder
{{alert.groups[0].keyValues.teamId}}retrieves theteamIdvalue from the first group in the alert.The resulting notification channel follows the format
teamId-interface(for example,engineering-interface,security-interface).
Using team name when a naming standard exists
This ensures the team name is formatted correctly by:
Converting it to lowercase (
lower).Replacing spaces with an empty string (
replace(from=' ', '')).
The resulting notification channel follows the format teamname-interface (for example, devops-interface).
Using team name when no naming standard exists
{% set first_group = alert.groups | first %}
{% if first_group is object %}
{% set team_name = first_group.keyValues | get(key='Team', default='-') %}
{% else %}
{% set team_name = "-" %}
{% endif %}
{% if team_name == "Supply" %}
supply-alerts
{% elif team_name == "Billing" %}
billing-alerts
{% else %}
techsupport_alerts
{% endif %}
This script determines the notification channel based on the team name in the alert metadata.
If a recognized team name is found, the alert is sent to a predefined channel:
"Supply"sends tosupply-alerts"Billing"sends tobilling-alerts
If no matching team name exists, the alert defaults to techsupport_alerts.