Skip to content

Commit 4650e18

Browse files
committed
docs update
1 parent edd0cbd commit 4650e18

3 files changed

Lines changed: 32 additions & 117 deletions

File tree

docs/configuration/sinks/slack.rst

Lines changed: 30 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -181,140 +181,63 @@ 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+
184186
Message Templating
185187
-------------------------------------------------------------------
186188

187189
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.
188190

189-
To use custom templates, add them to the ``custom_templates`` parameter:
191+
To use custom templates change your `slack_sink` to `slack_sink_preview`, and add your templates to the ``slack_custom_templates`` parameter:
190192

191193
.. code-block:: yaml
192194
193195
sinksConfig:
194-
- slack_sink:
195-
name: main_slack_sink
196-
slack_channel: "#alerts"
197-
api_key: xoxb-112...
198-
custom_templates:
199-
header.j2: |
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: |-
200202
{
201-
"type": "section",
203+
"type": "header",
202204
"text": {
203-
"type": "mrkdwn",
204-
"text": "{{ status_emoji }} *CUSTOM ALERT: {{ title }}*"
205+
"type": "plain_text",
206+
"text": "Custom Alert Format:\n {{ status_emoji }} [{{ status_text }}] {{ title }}",
207+
"emoji": true
205208
}
206209
}
207210
208211
{
209-
"type": "context",
210-
"elements": [
211-
{
212-
"type": "mrkdwn",
213-
"text": ":bell: {{ alert_type }} on cluster {{ cluster_name }}"
214-
},
215-
{
216-
"type": "mrkdwn",
217-
"text": "{{ severity_emoji }} {{ severity }}"
218-
}
219-
]
212+
"type": "divider"
220213
}
221214
222-
Templates use Slack's Block Kit format and must generate valid JSON. Each template block is separated by double newlines (``\n\n``).
223-
224-
Available template variables:
225-
226-
+-----------------------------+-------------------------------------------------------------+
227-
| Variable | Description |
228-
+=============================+=============================================================+
229-
| ``title`` | The alert title |
230-
+-----------------------------+-------------------------------------------------------------+
231-
| ``status_text`` | "Firing" or "Resolved" |
232-
+-----------------------------+-------------------------------------------------------------+
233-
| ``status_emoji`` | "⚠️" (for firing) or "✅" (for resolved) |
234-
+-----------------------------+-------------------------------------------------------------+
235-
| ``severity`` | Alert severity (e.g., "Warning", "Critical") |
236-
+-----------------------------+-------------------------------------------------------------+
237-
| ``severity_emoji`` | Emoji for the severity level |
238-
+-----------------------------+-------------------------------------------------------------+
239-
| ``alert_type`` | "Alert", "K8s Event", or "Notification" |
240-
+-----------------------------+-------------------------------------------------------------+
241-
| ``cluster_name`` | The name of the cluster |
242-
+-----------------------------+-------------------------------------------------------------+
243-
| ``platform_enabled`` | Boolean indicating if Robusta platform is enabled |
244-
+-----------------------------+-------------------------------------------------------------+
245-
| ``include_investigate_link``| Boolean for including investigate link |
246-
+-----------------------------+-------------------------------------------------------------+
247-
| ``investigate_uri`` | URI for investigation |
248-
+-----------------------------+-------------------------------------------------------------+
249-
| ``resource_text`` | Resource identifier (e.g., "Pod/namespace/name") |
250-
+-----------------------------+-------------------------------------------------------------+
251-
| ``resource_emoji`` | Emoji for the resource type |
252-
+-----------------------------+-------------------------------------------------------------+
253-
| ``finding`` | The complete finding object as JSON |
254-
+-----------------------------+-------------------------------------------------------------+
255-
256-
Currently available templates:
257-
258-
* ``header.j2`` - The header section of alert notificationsTemplate Styles and Customization
259-
-------------------------------------------------------------------
260-
261-
Slack messages in Robusta can be customized using different template styles and Jinja2 templates.
262-
263-
Template Styles
264-
~~~~~~~~~~~~~~
265-
266-
Robusta supports two built-in template styles:
267-
268-
1. **default** - Modern JIRA-style formatting (default)
269-
2. **legacy** - Classic formatting matching Robusta's original style
270-
271-
To select a template style:
272-
273-
.. code-block:: yaml
274-
275-
sinksConfig:
276-
- slack_sink:
277-
name: main_slack_sink
278-
slack_channel: "#alerts"
279-
api_key: xoxb-112...
280-
template_style: "legacy" # Use "default" or "legacy"
281-
282-
Custom Templates
283-
~~~~~~~~~~~~~~~
284-
285-
For complete control over message formatting, you can provide custom Jinja2 templates:
286-
287-
.. code-block:: yaml
288-
289-
sinksConfig:
290-
- slack_sink:
291-
name: main_slack_sink
292-
slack_channel: "#alerts"
293-
api_key: xoxb-112...
294-
custom_templates:
295-
header.j2: |
296215
{
297216
"type": "section",
298-
"text": {
299-
"type": "mrkdwn",
300-
"text": "{{ status_emoji }} *CUSTOM ALERT: {{ title }}*"
301-
}
302-
}
303-
304-
{
305-
"type": "context",
306-
"elements": [
217+
"fields": [
218+
{
219+
"type": "mrkdwn",
220+
"text": "*Type:* {{ alert_type }}"
221+
},
307222
{
308-
"type": "mrkdwn",
309-
"text": ":bell: {{ alert_type }} on cluster {{ cluster_name }}"
223+
"type": "mrkdwn",
224+
"text": "*Severity:* {{ severity_emoji }} {{ severity }}"
310225
},
311226
{
312227
"type": "mrkdwn",
313-
"text": "{{ severity_emoji }} {{ severity }}"
228+
"text": "*Cluster:* {{ cluster_name }}"
229+
}
230+
{% if resource_text %}
231+
,
232+
{
233+
"type": "mrkdwn",
234+
"text": "*Resource:*\n{{ resource_text }}"
314235
}
236+
{% endif %}
315237
]
316238
}
317239
240+
318241
Templates use Slack's Block Kit format and must generate valid JSON. Each template block is separated by double newlines (``\n\n``).
319242

320243
Available template variables:
@@ -336,10 +259,6 @@ Available template variables:
336259
+-----------------------------+-------------------------------------------------------------+
337260
| ``cluster_name`` | The name of the cluster |
338261
+-----------------------------+-------------------------------------------------------------+
339-
| ``platform_enabled`` | Boolean indicating if Robusta platform is enabled |
340-
+-----------------------------+-------------------------------------------------------------+
341-
| ``include_investigate_link``| Boolean for including investigate link |
342-
+-----------------------------+-------------------------------------------------------------+
343262
| ``investigate_uri`` | URI for investigation |
344263
+-----------------------------+-------------------------------------------------------------+
345264
| ``resource_text`` | Resource identifier (e.g., "Pod/namespace/name") |
@@ -349,6 +268,3 @@ Available template variables:
349268
| ``finding`` | The complete finding object with all alert data |
350269
+-----------------------------+-------------------------------------------------------------+
351270

352-
Currently available templates:
353-
354-
* ``header.j2`` - The header section of alert notifications

src/robusta/core/sinks/slack/preview/slack_sink_preview_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_custom_template(self) -> Optional[str]:
2828
Returns the custom template string for the effective template name, if it exists.
2929
"""
3030
if self.slack_custom_templates and len(self.slack_custom_templates) == 1:
31-
return next(iter(self.slack_custom_templates))
31+
return next(iter(self.slack_custom_templates.values()))
3232
return None
3333

3434

src/robusta/integrations/slack/sender.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ def __create_finding_header_preview(
491491
"include_investigate_link": include_investigate_link,
492492
"investigate_uri": investigate_uri,
493493
"resource_text": resource_text,
494-
"resource_emoji": resource_emoji,
495-
"finding": finding
494+
"resource_emoji": resource_emoji
496495
}
497496

498497
# Determine the template name to use

0 commit comments

Comments
 (0)