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

SMTP sink #1128

Merged
merged 1 commit into from
Oct 27, 2023
Merged

SMTP sink #1128

merged 1 commit into from
Oct 27, 2023

Conversation

RobertSzefler
Copy link
Contributor

@RobertSzefler RobertSzefler commented Oct 16, 2023

HTML layouts seem to be OK :)

@CLAassistant
Copy link

CLAassistant commented Oct 16, 2023

CLA assistant check
All committers have signed the CLA.


class MailTransformer(Transformer):
def __init__(self, *args, **kwargs):
super(MailTransformer).__init__(*args, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
super(MailTransformer).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

with patch("robusta.integrations.mail.sender.apprise") as mock_apprise:
sink.write_finding(finding, platform_enabled=True)
mock_apprise.Apprise.return_value.add.assert_called_once_with("mailtos://user:password@example.com?from=a@x&to=b@y")
expected_body = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just to use from unittest.mock import ANY?
I don't think checking for the exact body is helpfull, but it will 100% create some troubles when, for example, removing one space from the body

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -17,7 +17,8 @@ include_trailing_comma = true
python = "^3.7.1"
CairoSVG = "^2.5.2"
Flask = "^2.0.2"
prometheus-api-client = "^0.4.2"
#prometheus-api-client = "^0.4.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#prometheus-api-client = "^0.4.2"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@RobertSzefler RobertSzefler force-pushed the feature/smtp-sink branch 2 times, most recently from eb51510 to 2b3e6f2 Compare October 17, 2023 10:44
Copy link
Contributor

@arikalon1 arikalon1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @RobertSzefler

Left some minor comments

sinksConfig:
- mail_sink:
name: mail_sink
mailto: mailtos://user:password@server&from=a@x&to=b@y,c@z
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the value of mailto be under quotes? ("", since it has :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like having a : in a value is ok as long as it's not followed by a space (the YAML spec is weird), and indeed it works ok with PyYAML, but to be extra sure I added quotes and a warning in the docs.

self.file_blocks = []

def block_to_html(self, block: BaseBlock) -> str:
# TODO should we additionally support ScanReportBlock here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should
Any reason not to?
We can convert it to PDF and send it as a file attachment (like we do on Slack)
I think users will use it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it looks like the Slack sink is the only sink that handles ScanReportBlocks, so I was not sure if it's important at all. Will add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added support for ScanReportBlocks via PDF files, just as in the Slack sink. Additionally added a check & a warning in robusta.core.sinks.transformer

)
blocks.append(self.__create_finding_header(finding, status))
else:
# TODO is this correct? Is it possible for the finding to have no title at all?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not possible, and title is mandatory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the "else" part

f.write(file_block.contents)
attachments.add(f.name)
ap_obj.add(self.mailto)
logging.info(f"MailSender: sending title={finding.title}, body={html_body}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be too spammy, maybe change it to debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@RobertSzefler RobertSzefler force-pushed the feature/smtp-sink branch 3 times, most recently from e013478 to aa0fec6 Compare October 27, 2023 09:21
@RobertSzefler RobertSzefler merged commit 7c2b95f into master Oct 27, 2023
16 checks passed
@RobertSzefler RobertSzefler deleted the feature/smtp-sink branch October 27, 2023 13:27
anakaiti pushed a commit to BrioHR/robusta that referenced this pull request Oct 31, 2023
@Sheeproid Sheeproid linked an issue Oct 31, 2023 that may be closed by this pull request
pavangudiwada pushed a commit to pavangudiwada/robusta that referenced this pull request Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New sink: email
4 participants