@@ -181,3 +181,118 @@ your own. This is not recommended for most companies due to the added complexity
181181
182182 When using a custom Slack app, callback buttons are not supported due to complexities in how Slack handles incoming
183183 messages. :ref: `Contact us if you need assistance. <Getting Support >`
184+
185+
186+ Message Templating
187+ -------------------------------------------------------------------
188+
189+ Slack messages can be customized using Jinja2 templates. Robusta includes default templates that match the standard format, but you can override them for custom formatting.
190+
191+ To use custom templates change your `slack_sink ` to `slack_sink_preview `, and add your templates to the ``slack_custom_templates `` parameter:
192+
193+ .. code-block :: yaml
194+
195+ sinksConfig :
196+ - slack_sink_preview :
197+ api_key : xoxb-198...
198+ name : preview_slack_sink
199+ slack_channel : demo-slack-preview
200+ slack_custom_templates :
201+ custom_template.j2 : |-
202+ {
203+ "type": "header",
204+ "text": {
205+ "type": "plain_text",
206+ "text": "Custom Alert Format:\n {{ status_emoji }} [{{ status_text }}] {{ title }}",
207+ "emoji": true
208+ }
209+ }
210+
211+ {
212+ "type": "section",
213+ "text": {
214+ "type": "mrkdwn",
215+ "text": "{{ status_emoji }} *[{{ status_text }}] {{ title }}*{% if mention %} {{ mention }}{% endif %}"
216+ }
217+ }
218+
219+ {
220+ "type": "divider"
221+ }
222+
223+ {
224+ "type": "section",
225+ "fields": [
226+ {
227+ "type": "mrkdwn",
228+ "text": "*Type:* {{ alert_type }}"
229+ },
230+ {
231+ "type": "mrkdwn",
232+ "text": "*Severity:* {{ severity_emoji }} {{ severity }}"
233+ },
234+ {
235+ "type": "mrkdwn",
236+ "text": "*Cluster:* {{ cluster_name }}"
237+ }
238+ {% if resource_text %}
239+ ,
240+ {
241+ "type": "mrkdwn",
242+ "text": "*Resource:*\\n{{ resource_text }}"
243+ }
244+ {% endif %}
245+ ]
246+ }
247+
248+ {
249+ "type": "section",
250+ "text": {
251+ "type": "mrkdwn",
252+ "text": "{% if labels %}*Labels:*\\n\\n{% for key, value in labels.items() %}• *{{ key }}*: {{ value }}\\n\\n{% endfor %}{% else %}*Labels:* _None_{% endif %}"
253+ }
254+ }
255+
256+ Templates use Slack's Block Kit format and must generate valid JSON. Each template block is separated by double newlines (``\n\n ``).
257+
258+ Available template variables:
259+
260+ +-----------------------------+-------------------------------------------------------------+
261+ | Variable | Description |
262+ +=============================+=============================================================+
263+ | ``title `` | The alert title |
264+ +-----------------------------+-------------------------------------------------------------+
265+ | ``description `` | The alert description |
266+ +-----------------------------+-------------------------------------------------------------+
267+ | ``status_text `` | "Firing" or "Resolved" |
268+ +-----------------------------+-------------------------------------------------------------+
269+ | ``status_emoji `` | "⚠️" (for firing) or "✅" (for resolved) |
270+ +-----------------------------+-------------------------------------------------------------+
271+ | ``severity `` | Alert severity (e.g., "Warning", "Critical") |
272+ +-----------------------------+-------------------------------------------------------------+
273+ | ``severity_emoji `` | Emoji for the severity level |
274+ +-----------------------------+-------------------------------------------------------------+
275+ | ``alert_type `` | "Alert", "K8s Event", or "Notification" |
276+ +-----------------------------+-------------------------------------------------------------+
277+ | ``cluster_name `` | The name of the cluster |
278+ +-----------------------------+-------------------------------------------------------------+
279+ | ``investigate_uri `` | URI for investigation |
280+ +-----------------------------+-------------------------------------------------------------+
281+ | ``resource_text `` | Resource identifier (e.g., "Pod/namespace/name") |
282+ +-----------------------------+-------------------------------------------------------------+
283+ | ``subject_kind `` | The Kubernetes resource kind (e.g., "Pod", "Deployment") |
284+ +-----------------------------+-------------------------------------------------------------+
285+ | ``subject_namespace `` | The Kubernetes namespace |
286+ +-----------------------------+-------------------------------------------------------------+
287+ | ``subject_name `` | The name of the Kubernetes resource |
288+ +-----------------------------+-------------------------------------------------------------+
289+ | ``resource_emoji `` | Emoji for the resource type |
290+ +-----------------------------+-------------------------------------------------------------+
291+ | ``mention `` | Any @mentions extracted from the title |
292+ +-----------------------------+-------------------------------------------------------------+
293+ | ``labels `` | Kubernetes labels on the subject resource (dict) |
294+ +-----------------------------+-------------------------------------------------------------+
295+ | ``annotations `` | Kubernetes annotations on the subject resource (dict) |
296+ +-----------------------------+-------------------------------------------------------------+
297+ | ``fingerprint `` | The unique identifier for the alert |
298+ +-----------------------------+-------------------------------------------------------------+
0 commit comments