Skip to content

Commit

Permalink
improve formatting of summary messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Szefler committed Apr 15, 2024
1 parent a7c694e commit 61c1277
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions src/robusta/integrations/slack/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def __to_slack(self, block: BaseBlock, sink_name: str = None) -> List[SlackBlock
return self.__to_slack_links(block.links)
elif isinstance(block, ScanReportBlock):
raise AssertionError("to_slack() should never be called on a ScanReportBlock")
elif isinstance(block, dict):
return [block]
else:
logging.warning(f"cannot convert block of type {type(block)} to slack format block: {block}")
return [] # no reason to crash the entire report
Expand Down Expand Up @@ -433,26 +435,46 @@ def send_or_update_summary_message(
now_ts_utc_dt = datetime.fromtimestamp(now_ts).astimezone(tz.UTC)
formatted_now_ts = now_ts_utc_dt.strftime("%Y-%m-%d %H:%M UTC")
time_text = (
f"*Group time range:* <!date^{int(summary_start)}^{{date_num}} {{time}}|{formatted_summary_start}>"
f"*Time interval:* <!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)

blocks = [
MarkdownBlock("👀 Alert summary"),
MarkdownBlock(f"*Total alerts*: {n_total_alerts}"),
MarkdownBlock(f"*Matching criteria*: {group_by_criteria_str}"),
LinksBlock(
links=[
LinkProp(
text="Investigate 🔎",
url=investigate_uri,
)
]
),
MarkdownBlock(text=f"*Source:* `{self.cluster_name}`"),
MarkdownBlock(text=time_text),
table_block,
MarkdownBlock(f"*Alerts Summary - {n_total_alerts} Notifications*"),
]

source_txt = f"*Source:* `{self.cluster_name}`"
if platform_enabled:
blocks.extend([
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": source_txt,
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Investigate 🔎",
},
"value": "click_me_123", # FIXME
"action_id": "button-action", # FIXME
"url": investigate_uri,
},
}
])
else:
blocks.append(MarkdownBlock(text=source_txt))

blocks.extend(
[
MarkdownBlock(f"*Matching criteria*: {group_by_criteria_str}"),
MarkdownBlock(text=time_text),
table_block,
]
)
output_blocks = []
for block in blocks:
output_blocks.extend(self.__to_slack(block, sink_params.name))
Expand Down

0 comments on commit 61c1277

Please sign in to comment.