Skip to content
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

send alerts - added debug logs #1737

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading