4848from robusta .core .sinks .sink_base import KeyT
4949from robusta .core .sinks .slack .slack_sink_params import SlackSinkParams
5050from robusta .core .sinks .slack .preview .slack_sink_preview_params import SlackSinkPreviewParams
51-
51+ from robusta . model . config import Registry
5252from robusta .core .sinks .transformer import Transformer
5353
5454ACTION_TRIGGER_PLAYBOOK = "trigger_playbook"
@@ -62,7 +62,7 @@ class SlackSender:
6262 verified_api_tokens : Set [str ] = set ()
6363 channel_name_to_id = {}
6464
65- def __init__ (self , slack_token : str , account_id : str , cluster_name : str , signing_key : str , slack_channel : str , is_preview : bool = False ):
65+ def __init__ (self , slack_token : str , account_id : str , cluster_name : str , signing_key : str , slack_channel : str , registry : Registry , is_preview : bool = False ):
6666 """
6767 Connect to Slack and verify that the Slack token is valid.
6868 Return True on success, False on failure
@@ -80,6 +80,7 @@ def __init__(self, slack_token: str, account_id: str, cluster_name: str, signing
8080 timeout = SLACK_REQUEST_TIMEOUT ,
8181 retry_handlers = all_builtin_retry_handlers (),
8282 )
83+ self .registry = registry
8384 self .signing_key = signing_key
8485 self .account_id = account_id
8586 self .cluster_name = cluster_name
@@ -672,6 +673,15 @@ def send_finding_to_slack(
672673 thread_ts = thread_ts
673674 )
674675
676+ def __is_holmes_slackbot_enabled (self ) -> bool :
677+ robusta_sinks = self .registry .get_sinks ().get_robusta_sinks ()
678+ if not robusta_sinks :
679+ logging .debug ("No robusta sinks found, holmes not connected to slackbot" )
680+ return False
681+
682+ robusta_sink = robusta_sinks [0 ]
683+ return robusta_sink .is_holmes_slackbot_connected ()
684+
675685 def __send_finding_to_slack (
676686 self ,
677687 finding : Finding ,
@@ -731,7 +741,8 @@ def __send_finding_to_slack(
731741
732742 blocks .append (DividerBlock ())
733743
734- holmes_block = self .get_holmes_block (platform_enabled , HOLMES_ENABLED )
744+ is_holmes_slackbot_enabled = self .__is_holmes_slackbot_enabled ()
745+ holmes_block = self .get_holmes_block (platform_enabled , is_holmes_slackbot_enabled )
735746 if holmes_block :
736747 blocks .append (holmes_block )
737748
0 commit comments