Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Szefler committed Apr 15, 2024
1 parent 78c1298 commit a7c694e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/robusta/core/sinks/sink_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, sink_params: SinkBaseParams, registry):
if sink_params.grouping.notification_mode.summary.by:
for attr in sink_params.grouping.notification_mode.summary.by:
if isinstance(attr, str):
self.finding_summary_header.append("reason" if attr == "identifier" else attr)
self.finding_summary_header.append("notification" if attr == "identifier" else attr)
elif isinstance(attr, dict):
keys = list(attr.keys())
if len(keys) > 1:
Expand Down
4 changes: 2 additions & 2 deletions src/robusta/core/sinks/slack/slack_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def classify_finding(self, finding_data: Dict, attributes: List) -> Tuple[Tuple[
continue
values += (finding_data.get(attr),)
descriptions.append(
f"*{'Notification' if attr=='identifier' else attr}*: {self.display_value(finding_data.get(attr))}"
f"{'notification' if attr=='identifier' else attr}: {self.display_value(finding_data.get(attr))}"
)
elif isinstance(attr, dict):
# This is typically labels and annotations
Expand All @@ -140,7 +140,7 @@ def classify_finding(self, finding_data: Dict, attributes: List) -> Tuple[Tuple[
for subattr_name in sorted(attr[top_level_attr_name]):
subvalues.append((subattr_name, finding_data.get(top_level_attr_name, {}).get(subattr_name)))
subvalues_str = ", ".join(f"{key}={self.display_value(value)}" for key, value in sorted(subvalues))
descriptions.append(f"*{top_level_attr_name}*: {subvalues_str}")
descriptions.append(f"{top_level_attr_name}: {subvalues_str}")
return values, descriptions

def display_value(self, value):
Expand Down
19 changes: 13 additions & 6 deletions src/robusta/integrations/slack/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,11 @@ def send_or_update_summary_message(
f"*Group time range:* <!date^{int(summary_start)}^{{date_num}} {{time}}|{formatted_summary_start}>"
f" to <!date^{int(now_ts)}^{{date_num}} {{time}}|{formatted_now_ts}>"
)
group_by_criteria_str = ", ".join(f"`header`" for header in group_by_classification_header)
group_by_criteria_str = ", ".join(f"`{header}`" for header in group_by_classification_header)
blocks = [
MarkdownBlock("👀 Alert summary"),
MarkdownBlock(f"Total alerts: {n_total_alerts}"),
MarkdownBlock(f"Matching criteria: {group_by_criteria_str}"),
MarkdownBlock(f"*Total alerts*: {n_total_alerts}"),
MarkdownBlock(f"*Matching criteria*: {group_by_criteria_str}"),
LinksBlock(
links=[
LinkProp(
Expand All @@ -457,7 +457,16 @@ def send_or_update_summary_message(
for block in blocks:
output_blocks.extend(self.__to_slack(block, sink_params.name))

channel = sink_params.get_slack_channel(self.cluster_name, {}, {})
# TODO for the purpose of summary messages, we assume the chanel is determined as if
# labels and annotations were empty, bypassing the elaborate logic in ChannelTransformer.
# Is this acceptable? I don't really see a way around this.
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 All @@ -476,8 +485,6 @@ def send_or_update_summary_message(

try:
resp = method(
# TODO: for the purpose of the summary, we pretend labels and annotations are empty. Is this okay?
# There's some convoluted logic in get_slack_channel that takes this into consideration.
channel=channel,
text="Summary for: " + ", ".join(group_by_classification_header),
blocks=output_blocks,
Expand Down

0 comments on commit a7c694e

Please sign in to comment.