Skip to content

Commit 7ed76b5

Browse files
authored
ROB-1268: Alert limitation (#1809)
* update note about the alert limitation * fix log docs title fix but when mentioning a slack user in summary * fix but when mentioning a slack user in summary * CR fixes * fix import
1 parent b4ade0a commit 7ed76b5

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

docs/playbook-reference/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
automatic-remediation-examples/index
1313
prometheus-examples/index
1414
kubernetes-examples/index
15-
logs-triggers/index
15+
Log Based Alerting <logs-triggers/index>

docs/playbook-reference/logs-triggers/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
Automate Responses to Application Logs
2-
==========================================
1+
:hide-toc:
2+
3+
Log-based alerting and auto-remediation with fluentbit, prometheus, and robusta
4+
==================================================================================
35

46
This tutorial walks you through building an automation that detects specific patterns in Kubernetes pod logs and responds automatically.
57

src/robusta/integrations/slack/sender.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import ssl
44
import tempfile
5+
import re
56
from datetime import datetime, timedelta
67
from itertools import chain
78
from typing import Any, Dict, List, Optional, Set
@@ -52,6 +53,7 @@
5253
ACTION_LINK = "link"
5354
SlackBlock = Dict[str, Any]
5455
MAX_BLOCK_CHARS = 3000
56+
MENTION_PATTERN = re.compile(r"<[^>]+>")
5557

5658

5759
class SlackSender:
@@ -407,10 +409,25 @@ def __create_holmes_callback(self, finding: Finding) -> CallbackBlock:
407409
}
408410
)
409411

412+
@staticmethod
413+
def extract_mentions(title) -> (str, str):
414+
mentions = MENTION_PATTERN.findall(title)
415+
416+
mention = ""
417+
if mentions:
418+
mention = " " + " ".join(mentions)
419+
title = MENTION_PATTERN.sub("", title).strip()
420+
421+
return title, mention
422+
423+
410424
def __create_finding_header(
411425
self, finding: Finding, status: FindingStatus, platform_enabled: bool, include_investigate_link: bool
412426
) -> MarkdownBlock:
413427
title = finding.title.removeprefix("[RESOLVED] ")
428+
429+
title, mention = self.extract_mentions(title)
430+
414431
sev = finding.severity
415432
if finding.source == FindingSource.PROMETHEUS:
416433
status_name: str = (
@@ -426,7 +443,7 @@ def __create_finding_header(
426443
title = f"<{finding.get_investigate_uri(self.account_id, self.cluster_name)}|*{title}*>"
427444
return MarkdownBlock(
428445
f"""{status_name} {sev.to_emoji()} *{sev.name.capitalize()}*
429-
{title}"""
446+
{title}{mention}"""
430447
)
431448

432449
def __create_links(

tests/slack/test_slack_mentions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from robusta.integrations.slack import SlackSender
2+
3+
4+
def test_title_without_mentions():
5+
title = "Title with no mentions"
6+
new_title, mention = SlackSender.extract_mentions(title)
7+
assert new_title == title
8+
assert mention == ""
9+
10+
def test_title_with_single_mention():
11+
title = "Title with single mention <@U024BE7LH>"
12+
new_title, mention = SlackSender.extract_mentions(title)
13+
assert new_title == "Title with single mention"
14+
assert mention == " <@U024BE7LH>"
15+
16+
def test_title_with_two_mentions():
17+
title = "Title with <@U024BE7LG> two mentions <@U024BE7LH>"
18+
new_title, mention = SlackSender.extract_mentions(title)
19+
assert new_title == "Title with two mentions"
20+
assert mention == " <@U024BE7LG> <@U024BE7LH>"

0 commit comments

Comments
 (0)