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
2 changes: 1 addition & 1 deletion docs/playbook-reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
automatic-remediation-examples/index
prometheus-examples/index
kubernetes-examples/index
logs-triggers/index
Log Based Alerting <logs-triggers/index>
6 changes: 4 additions & 2 deletions docs/playbook-reference/logs-triggers/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Automate Responses to Application Logs
==========================================
:hide-toc:

Log-based alerting and auto-remediation with fluentbit, prometheus, and robusta
==================================================================================

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

Expand Down
19 changes: 18 additions & 1 deletion src/robusta/integrations/slack/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import ssl
import tempfile
import re
from datetime import datetime, timedelta
from itertools import chain
from typing import Any, Dict, List, Optional, Set
Expand Down Expand Up @@ -52,6 +53,7 @@
ACTION_LINK = "link"
SlackBlock = Dict[str, Any]
MAX_BLOCK_CHARS = 3000
MENTION_PATTERN = re.compile(r"<[^>]+>")


class SlackSender:
Expand Down Expand Up @@ -407,10 +409,25 @@ def __create_holmes_callback(self, finding: Finding) -> CallbackBlock:
}
)

@staticmethod
def extract_mentions(title) -> (str, str):
mentions = MENTION_PATTERN.findall(title)

mention = ""
if mentions:
mention = " " + " ".join(mentions)
title = MENTION_PATTERN.sub("", title).strip()

return title, mention


def __create_finding_header(
self, finding: Finding, status: FindingStatus, platform_enabled: bool, include_investigate_link: bool
) -> MarkdownBlock:
title = finding.title.removeprefix("[RESOLVED] ")

title, mention = self.extract_mentions(title)

sev = finding.severity
if finding.source == FindingSource.PROMETHEUS:
status_name: str = (
Expand All @@ -426,7 +443,7 @@ def __create_finding_header(
title = f"<{finding.get_investigate_uri(self.account_id, self.cluster_name)}|*{title}*>"
return MarkdownBlock(
f"""{status_name} {sev.to_emoji()} *{sev.name.capitalize()}*
{title}"""
{title}{mention}"""
Comment thread
arikalon1 marked this conversation as resolved.
)

def __create_links(
Expand Down
20 changes: 20 additions & 0 deletions tests/slack/test_slack_mentions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from robusta.integrations.slack import SlackSender


def test_title_without_mentions():
title = "Title with no mentions"
new_title, mention = SlackSender.extract_mentions(title)
assert new_title == title
assert mention == ""

def test_title_with_single_mention():
title = "Title with single mention <@U024BE7LH>"
new_title, mention = SlackSender.extract_mentions(title)
assert new_title == "Title with single mention"
assert mention == " <@U024BE7LH>"

def test_title_with_two_mentions():
title = "Title with <@U024BE7LG> two mentions <@U024BE7LH>"
new_title, mention = SlackSender.extract_mentions(title)
assert new_title == "Title with two mentions"
Comment thread
arikalon1 marked this conversation as resolved.
assert mention == " <@U024BE7LG> <@U024BE7LH>"
Loading