Skip to content

Commit ed438ac

Browse files
Auto-detect Power Automate URLs and disable file attachments
- Change send_files from bool to Optional[bool] with None default - Add _is_power_automate_url() helper to detect Power Automate webhooks - Auto-disable files for Power Automate URLs (*.api.powerplatform.com) - Keep files enabled for legacy webhooks (*.webhook.office.com) - Explicit send_files: true/false always overrides auto-detection - Update documentation with auto-detection behavior
1 parent 9f27b8d commit ed438ac

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

docs/configuration/sinks/ms-teams.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,33 @@ For example:
9595
webhook_url: teams-incoming-webhook
9696
prefer_redirect_to_platform: false
9797
98-
Disabling File Attachments
98+
File Attachments
9999
-------------------------------------------------------------------
100100

101101
MS Teams Power Automate workflow webhooks have a strict 28KB payload size limit.
102-
Alerts with embedded files (graphs, images, logs) may exceed this limit.
102+
Robusta automatically detects Power Automate URLs and disables file attachments
103+
to avoid exceeding this limit.
103104

104-
To disable file attachments and reduce payload size, set ``send_files: false``:
105+
**Auto-detection behavior:**
106+
107+
- Power Automate URLs (``*.api.powerplatform.com``): files disabled by default
108+
- Legacy webhook URLs (``*.webhook.office.com``): files enabled by default
109+
110+
**Override auto-detection:**
111+
112+
You can explicitly control file attachments using the ``send_files`` parameter:
105113

106114
.. code-block:: yaml
107115
108116
sinksConfig:
109117
- ms_teams_sink:
110118
name: main_ms_teams_sink
111119
webhook_url: teams-incoming-webhook
112-
send_files: false # Disables all file attachments to reduce payload size
120+
send_files: true # Force enable files (override auto-detection)
121+
# send_files: false # Force disable files
113122
114123
.. note::
115124

116-
When ``send_files`` is false, all file attachments (images, logs, etc.)
117-
will not be included in the MS Teams message. Text-based content will still
118-
be sent normally.
125+
When ``send_files`` is false (or auto-detected as false for Power Automate),
126+
all file attachments (images, logs, graphs, etc.) will not be included in
127+
the MS Teams message. Text-based content will still be sent normally.

src/robusta/core/sinks/msteams/msteams_sink_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class MsTeamsSinkParams(SinkBaseParams):
1111
webhook_url: str
1212
webhook_override: Optional[str] = None
13-
send_files: bool = True # Set False to disable file attachments (avoids 28KB limit)
13+
send_files: Optional[bool] = None # Auto-detect: False for Power Automate, True for legacy
1414

1515
@classmethod
1616
def _get_sink_type(cls):

src/robusta/integrations/msteams/sender.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Optional
23

34
from robusta.core.reporting import (
45
BaseBlock,
@@ -18,6 +19,15 @@
1819
from robusta.integrations.msteams.msteams_msg import MsTeamsMsg
1920

2021

22+
def _is_power_automate_url(url: str) -> bool:
23+
"""Check if URL is a Power Automate workflow webhook (has 28KB payload limit).
24+
25+
Power Automate URLs contain '.api.powerplatform.com' or '/powerautomate/'.
26+
Legacy connector URLs use '*.webhook.office.com' and don't have the 28KB limit.
27+
"""
28+
return ".api.powerplatform.com" in url or "/powerautomate/" in url
29+
30+
2131
class MsTeamsSender:
2232
@classmethod
2333
def __to_ms_teams(cls, block: BaseBlock, msg: MsTeamsMsg):
@@ -61,7 +71,7 @@ def send_finding_to_ms_teams(
6171
account_id: str,
6272
webhook_override: str,
6373
prefer_redirect_to_platform: bool,
64-
send_files: bool = True,
74+
send_files: Optional[bool] = None,
6575
):
6676
"""Send a finding to MS Teams via webhook.
6777
@@ -73,12 +83,18 @@ def send_finding_to_ms_teams(
7383
account_id: The Robusta account ID.
7484
webhook_override: Optional webhook URL override pattern.
7585
prefer_redirect_to_platform: Whether to prefer platform links over Prometheus.
76-
send_files: Whether to include file attachments. When False, all files
77-
are filtered out to avoid exceeding MS Teams 28KB payload limit.
86+
send_files: Whether to include file attachments. None (default) auto-detects
87+
based on webhook URL: disabled for Power Automate (28KB limit), enabled
88+
for legacy webhooks. Explicit True/False overrides auto-detection.
7889
"""
7990
webhook_url = MsTeamsWebhookUrlTransformer.template(
8091
webhook_override=webhook_override, default_webhook_url=webhook_url, annotations=finding.subject.annotations
8192
)
93+
94+
# Auto-detect send_files based on webhook URL if not explicitly set
95+
if send_files is None:
96+
send_files = not _is_power_automate_url(webhook_url)
97+
8298
msg = MsTeamsMsg(webhook_url, prefer_redirect_to_platform)
8399
msg.write_title_and_desc(platform_enabled, finding, cluster_name, account_id)
84100

0 commit comments

Comments
 (0)