-
Notifications
You must be signed in to change notification settings - Fork 308
Slack sink replies to a thread with holmes analysis #1799
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
Changes from all commits
e0ba4d3
d3d9ae5
fcbe55b
f9a9601
b7b845c
ef87d64
cf9576f
8a782ab
506209f
f82e7e5
c0200f0
38c8ce4
609d8f2
4a9250f
da274fe
c1042a8
997a9ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,10 @@ class ResourceInfo(BaseModel): | |
| class HolmesParams(ActionParams): | ||
| holmes_url: Optional[str] | ||
| model: Optional[str] | ||
| # Additional internal context that helps runner to send investigation to appropriate sinks | ||
| # for now it is used only for passing thread_ts to slack sink internally; | ||
| robusta_context: Optional[Dict[str, Any]] = None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking here loud, we already have SlackCallbackParams which being used in other flows. I think it will be good idea to add relevant info there and reuse in relevant flows. |
||
|
|
||
| @validator("holmes_url", allow_reuse=True) | ||
| def validate_protocol(cls, v): | ||
| if v and not v.startswith("http"): # if the user configured url without http(s) | ||
|
|
@@ -113,6 +117,7 @@ class AIInvestigateParams(HolmesParams): | |
| stream: bool = False | ||
|
|
||
|
|
||
|
|
||
| class HolmesToolsResult(BaseModel): | ||
| """ | ||
| :var name: Name of the tool. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,13 @@ def ask_holmes(event: ExecutionBaseEvent, params: AIInvestigateParams): | |
| finding.add_enrichment( | ||
| [HolmesResultsBlock(holmes_result=holmes_result)], enrichment_type=EnrichmentType.ai_analysis | ||
| ) | ||
|
|
||
| runner_context = getattr(params, "robusta_context", None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we are ignoring the sink param in this flow. It might cause issues with sending the finding to other sinks as well. I think we need to support the sink param in this flow as well. |
||
| if runner_context: | ||
| if "thread_ts" in runner_context: | ||
| finding.robusta_context["thread_ts"] = runner_context.get("thread_ts") | ||
| if "channel_id" in runner_context: | ||
| finding.robusta_context["channel_id"] = runner_context.get("channel_id") | ||
|
|
||
| event.add_finding(finding) | ||
|
|
||
| except Exception as e: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,7 +115,7 @@ def __get_action_block_for_choices(self, sink: str, choices: Dict[str, CallbackC | |
| ).json(), | ||
| } | ||
| ) | ||
|
|
||
| return [{"type": "actions", "elements": buttons}] | ||
|
|
||
| def __to_slack_links(self, links: List[LinkProp]) -> List[SlackBlock]: | ||
|
|
@@ -568,25 +568,45 @@ def send_holmes_analysis( | |
|
|
||
| except Exception: | ||
| logging.exception(f"error sending message to slack. {title}") | ||
|
|
||
| def _resolve_slack_thread( | ||
| self, | ||
| finding: Finding, | ||
| sink_params: SlackSinkParams, | ||
| thread_ts: Optional[str] = None, | ||
| ) -> tuple[str, Optional[str]]: | ||
|
|
||
| channel = ChannelTransformer.template( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A. Any reason to call this if channel override was provided? |
||
| sink_params.channel_override, | ||
| sink_params.slack_channel, | ||
| self.cluster_name, | ||
| finding.subject.labels, | ||
| finding.subject.annotations, | ||
| ) | ||
|
|
||
| ctx = getattr(finding, "robusta_context", {}) or {} | ||
| thread_override = ctx.get("thread_ts") | ||
| channel_override = ctx.get("channel_id") | ||
|
|
||
| return ( | ||
| channel_override or channel, | ||
| thread_override or thread_ts, | ||
| ) | ||
|
|
||
| def send_finding_to_slack( | ||
| self, | ||
| finding: Finding, | ||
| sink_params: SlackSinkParams, | ||
| platform_enabled: bool, | ||
| thread_ts: str = None, | ||
| thread_ts: Optional[str] = None, | ||
| ) -> str: | ||
| blocks: List[BaseBlock] = [] | ||
| attachment_blocks: List[BaseBlock] = [] | ||
|
|
||
| slack_channel = ChannelTransformer.template( | ||
| sink_params.channel_override, | ||
| sink_params.slack_channel, | ||
| self.cluster_name, | ||
| finding.subject.labels, | ||
| finding.subject.annotations, | ||
| slack_channel, thread_ts = self._resolve_slack_thread( | ||
| finding, sink_params, thread_ts | ||
| ) | ||
|
|
||
| if finding.finding_type == FindingType.AI_ANALYSIS: | ||
| # holmes analysis message needs special handling | ||
| self.send_holmes_analysis(finding, slack_channel, platform_enabled, thread_ts) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests