Skip to content

Commit

Permalink
add a work around for sending messages to slack via webhook (#1430)
Browse files Browse the repository at this point in the history
  • Loading branch information
romga and romg67 authored May 20, 2024
1 parent 6d63c9d commit 4494f3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/robusta/core/sinks/webhook/webhook_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, sink_config: WebhookSinkConfigWrapper, registry):
else None
)
self.size_limit = sink_config.webhook_sink.size_limit
self.slack_webhook = sink_config.webhook_sink.slack_webhook

def write_finding(self, finding: Finding, platform_enabled: bool):
if self.format == "text":
Expand Down Expand Up @@ -91,7 +92,13 @@ def __write_json(self, finding: Finding, platform_enabled: bool):
message_length += pair_length
else:
break

if self.slack_webhook:
message = {
"text": f"*Title:* {message['title']}\n"
f"*Description:* {message['description']}\n"
f"*Failure:* {message['failure']}\n"
f"*Aggregation Key:* {message['aggregation_key']}\n"
}
try:
r = requests.post(self.url, json=message, headers=self.headers)
r.raise_for_status()
Expand Down
1 change: 1 addition & 0 deletions src/robusta/core/sinks/webhook/webhook_sink_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class WebhookSinkParams(SinkBaseParams):
size_limit: int = 4096
authorization: SecretStr = None
format: str = "text"
slack_webhook: bool = False

@classmethod
def _get_sink_type(cls):
Expand Down

0 comments on commit 4494f3a

Please sign in to comment.