Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/robusta/core/sinks/slack/slack_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from robusta.core.model.env_vars import ROBUSTA_UI_DOMAIN
from robusta.core.reporting.base import Finding, FindingStatus
from robusta.core.sinks.common.channel_transformer import ChannelTransformer
from robusta.core.sinks.sink_base import NotificationGroup, NotificationSummary, SinkBase
from robusta.core.sinks.slack.slack_sink_params import SlackSinkConfigWrapper, SlackSinkParams
from robusta.integrations import slack as slack_module
Expand Down Expand Up @@ -47,10 +48,26 @@ def handle_notification_grouping(self, finding: Finding, platform_enabled: bool)
finding_data["cluster"] = self.cluster_name
resolved = finding.title.startswith("[RESOLVED]")

# Resolve the channel for this finding so we can include it in the group key.
# This ensures findings routed to different channels (via channel_override with
# labels/annotations) are grouped separately per channel.
Comment thread
arikalon1 marked this conversation as resolved.
resolved_channel = ChannelTransformer.template(
self.params.channel_override,
self.params.slack_channel,
self.cluster_name,
finding.subject.labels,
finding.subject.annotations,
)
Comment thread
arikalon1 marked this conversation as resolved.

# 1. Notification accounting
group_key, group_header = self.get_group_key_and_header(
finding_data, self.params.grouping.group_by
)
# Include the resolved channel in the group key so that findings destined
# for different channels (e.g. due to label-based channel_override) get
# separate groups, summary messages, and threads.
if self.params.channel_override:
group_key = group_key + (resolved_channel,)

if self.grouping_summary_mode:
summary_key, _ = self.get_group_key_and_header(
Expand All @@ -71,6 +88,7 @@ def handle_notification_grouping(self, finding: Finding, platform_enabled: bool)
msg_ts=notification_summary.message_id,
investigate_uri=investigate_uri,
grouping_interval=self.params.grouping.interval,
channel=resolved_channel,
)
notification_summary.message_id = slack_thread_ts
should_send_notification = self.params.grouping.notification_mode.summary.threaded
Expand Down
18 changes: 10 additions & 8 deletions src/robusta/integrations/slack/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ def send_or_update_summary_message(
msg_ts: str = None, # message identifier (for updates)
investigate_uri: str = None,
grouping_interval: int = None, # in seconds
channel: str = None, # pre-resolved channel (when channel_override uses labels/annotations)
):
"""Create or update a summary message with tabular information about the amount of events
fired/resolved and a header describing the event group that this information concerns."""
Expand Down Expand Up @@ -927,14 +928,15 @@ def send_or_update_summary_message(
for block in blocks:
output_blocks.extend(self.__to_slack(block, sink_params.name))

# For grouped notifications, channel override is supported only with the `cluster` attribute
channel = ChannelTransformer.template(
sink_params.channel_override,
sink_params.slack_channel,
self.cluster_name,
{},
{},
)
if not channel:
# Fallback: resolve channel without labels/annotations (only cluster_name will work)
channel = ChannelTransformer.template(
sink_params.channel_override,
sink_params.slack_channel,
self.cluster_name,
{},
{},
)
if msg_ts is not None:
method = self.slack_client.chat_update
kwargs = {"ts": msg_ts}
Expand Down
Loading