Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
from elementary.monitor.alerts.test_alert import TestAlertModel
from elementary.monitor.api.alerts.alert_filters import filter_alerts
from elementary.monitor.api.alerts.alerts import AlertsAPI
from elementary.monitor.data_monitoring.alerts.integrations.base_integration import (
BaseIntegration,
)
from elementary.monitor.data_monitoring.alerts.integrations.integrations import (
Integrations,
)
Expand Down Expand Up @@ -55,7 +58,7 @@ def get_health_check_message() -> MessageBody:


class DataMonitoringAlerts(DataMonitoring):
alerts_integration: BaseMessagingIntegration
alerts_integration: Union[BaseMessagingIntegration, BaseIntegration]

def __init__(
self,
Expand Down Expand Up @@ -87,7 +90,7 @@ def __init__(

def _get_integration_client(
self,
) -> BaseMessagingIntegration:
) -> Union[BaseMessagingIntegration, BaseIntegration]:
return Integrations.get_integration(
config=self.config,
tracking=self.tracking,
Expand Down Expand Up @@ -284,6 +287,11 @@ def _send_message(
return integration.send_message(destination=destination, body=body)

def _send_test_message(self) -> MessageSendResult:
if isinstance(self.alerts_integration, BaseIntegration):
raise ValueError(
"Cannot send test message with a BaseIntegration of type "
f"{type(self.alerts_integration)}"
)
test_message = get_health_check_message()
return self._send_message(
integration=self.alerts_integration, body=test_message, metadata={}
Expand All @@ -298,7 +306,9 @@ def _send_alert(
GroupedByTableAlerts,
AlertsGroup,
],
):
) -> bool:
if isinstance(self.alerts_integration, BaseIntegration):
return self.alerts_integration.send_alert(alert)
alert_message_builder = AlertMessageBuilder()
alert_message_body = alert_message_builder.build(
alert=alert,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, cast
from typing import Any, Optional, Union, cast

from elementary.config.config import Config
from elementary.exceptions.exceptions import Error
Expand All @@ -15,6 +15,12 @@
from elementary.messages.messaging_integrations.teams_webhook import (
TeamsWebhookMessagingIntegration,
)
from elementary.monitor.data_monitoring.alerts.integrations.base_integration import (
BaseIntegration,
)
from elementary.monitor.data_monitoring.alerts.integrations.slack.slack import (
SlackIntegration,
)
from elementary.tracking.tracking_interface import Tracking
from elementary.utils.log import get_logger

Expand All @@ -35,8 +41,13 @@ class Integrations:
def get_integration(
config: Config,
tracking: Optional[Tracking] = None,
) -> BaseMessagingIntegration:
) -> Union[BaseMessagingIntegration, BaseIntegration]:
if config.has_slack:
if config.is_slack_workflow:
return SlackIntegration(
config=config,
tracking=tracking,
)
if config.slack_token:
return SlackWebMessagingIntegration.from_token(
config.slack_token, tracking
Expand Down