Skip to content

Commit

Permalink
send alerts - added debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaKerman committed Nov 5, 2024
1 parent 9c66df0 commit 3d92557
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions elementary/clients/slack/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def create_client(
if not config.has_slack:
return None
if config.slack_token:
logger.debug("Creating Slack client with token.")
return SlackWebClient(token=config.slack_token, tracking=tracking)
elif config.slack_webhook:
logger.debug("Creating Slack client with webhook.")
return SlackWebhookClient(webhook=config.slack_webhook, tracking=tracking)
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ def send_alert(
) -> bool:
integration_params = self._get_integration_params(alert=alert)
channel_name = integration_params.get("channel")
logger.debug(f"Sending alert to Slack channel: {channel_name}")
try:
self._fix_owners_and_subscribers(alert)
template = self._get_alert_template(alert)
Expand Down Expand Up @@ -1156,18 +1157,15 @@ def _get_integration_params(
) -> Dict[str, Any]:
integration_params = dict()
if isinstance(self.client, SlackWebClient):
integration_params.update(
dict(
channel=(
self.config.slack_channel_name
if self.override_config_defaults
else (
alert.unified_meta.get("channel")
or self.config.slack_channel_name
)
)
)
)
if self.override_config_defaults:
channel = self.config.slack_channel_name
logger.debug(f"Using override config default channel: {channel}")
elif alert.unified_meta.get("channel"):
channel = alert.unified_meta.get("channel")
logger.debug(f"Using channel from meta: {channel}")
else:
channel = self.config.slack_channel_name
integration_params.update({"channel": channel})
return integration_params

def _create_single_alert_details_blocks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ def send_alert(
**kwargs,
) -> bool:
try:
logger.debug("Sending alert via Teams.")
self._get_alert_template(alert)
sent_successfully = self.client.send_message()
except Exception as e:
Expand Down

0 comments on commit 3d92557

Please sign in to comment.