Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make header information in mails sent by the mail sink optional (MAIN-1854) #1491

Merged
merged 1 commit into from
Jul 9, 2024
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
5 changes: 5 additions & 0 deletions docs/configuration/sinks/mail.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Configuring the mail sink
- mail_sink:
name: mail_sink
mailto: "mailtos://user:password@server&from=a@x&to=b@y,c@z"
with_header: false # optional

The default value of the optional `with_header` parameter is `true`. If set to `false`, mails
sent by this sink will *not* include header information, such as the finding header, investigate
button and the source of the notification.

.. note::

Expand Down
2 changes: 1 addition & 1 deletion src/robusta/core/sinks/mail/mail_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def __init__(self, sink_config: MailSinkConfigWrapper, registry):
)

def write_finding(self, finding: Finding, platform_enabled: bool):
self.sender.send_finding(finding, platform_enabled)
self.sender.send_finding(finding, platform_enabled, self.params.with_header)
3 changes: 3 additions & 0 deletions src/robusta/core/sinks/mail/mail_sink_params.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pydantic import validator

from robusta.core.sinks.sink_base_params import SinkBaseParams
Expand All @@ -6,6 +8,7 @@

class MailSinkParams(SinkBaseParams):
mailto: str
with_header: Optional[bool] = True

@classmethod
def _get_sink_type(cls):
Expand Down
12 changes: 7 additions & 5 deletions src/robusta/integrations/mail/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ def __init__(self, mailto: str, account_id: str, cluster_name: str, signing_key:
self.account_id = account_id
self.cluster_name = cluster_name

def send_finding(self, finding: Finding, platform_enabled: bool):
def send_finding(self, finding: Finding, platform_enabled: bool, include_headers: bool):
blocks: List[BaseBlock] = []

status: FindingStatus = (
FindingStatus.RESOLVED if finding.title.startswith("[RESOLVED]") else FindingStatus.FIRING
)
blocks.append(self.__create_finding_header(finding, status))

if platform_enabled:
blocks.append(self.create_links(finding, html_class="header_links"))
if include_headers:
blocks.append(self.__create_finding_header(finding, status))
if platform_enabled:
blocks.append(self.create_links(finding, html_class="header_links"))

blocks.append(MarkdownBlock(text=f"*Source:* `{self.cluster_name}`"))

blocks.append(MarkdownBlock(text=f"*Source:* `{self.cluster_name}`"))
if finding.description:
if finding.source == FindingSource.PROMETHEUS:
blocks.append(MarkdownBlock(f"{Emojis.Alert.value} *Alert:* {finding.description}"))
Expand Down
Loading