Returns a logger based on whether the NotificationBlock
is called from within a flow or task run context.
If a run context is present, the logger property returns a run logger.
Else, it returns a default logger labeled with the class’s name.Returns:
The run logger or a default logger with the class’s name.
Enables sending notifications via a provided Slack webhook.Supports both standard Slack webhooks (hooks.slack.com) and Slack GovCloud
webhooks (hooks.slack-gov.com).Examples:Load a saved Slack webhook and send a message:
from prefect.blocks.notifications import SlackWebhookslack_webhook_block = SlackWebhook.load("BLOCK_NAME")slack_webhook_block.notify("Hello from Prefect!")
Initialize the Slack webhook client.This method handles both standard Slack webhooks and Slack GovCloud webhooks.
Apprise’s built-in Slack plugin only supports hooks.slack.com, so we need to
manually construct the NotifySlack instance for slack-gov.com URLs to ensure
notifications are sent to the correct host.See: https://github.com/caronc/apprise/issues/XXXX (upstream issue)
Enables sending notifications via a provided Microsoft Teams webhook.Examples:Load a saved Teams webhook and send a message:
from prefect.blocks.notifications import MicrosoftTeamsWebhookteams_webhook_block = MicrosoftTeamsWebhook.load("BLOCK_NAME")teams_webhook_block.notify("Hello from Prefect!")
Enables sending notifications via a provided PagerDuty webhook.
See Apprise notify_pagerduty docs
for more info on formatting the URL.Examples:Load a saved PagerDuty webhook and send a message:
from prefect.blocks.notifications import PagerDutyWebHookpagerduty_webhook_block = PagerDutyWebHook.load("BLOCK_NAME")pagerduty_webhook_block.notify("Hello from Prefect!")
Apprise will combine subject and body by default, so we need to move
the body into the custom_details field. custom_details is part of the
webhook url, so we need to update the url and restart the client.
Apprise will combine subject and body by default, so we need to move
the body into the custom_details field. custom_details is part of the
webhook url, so we need to update the url and restart the client.
Enables sending notifications via Twilio SMS.
Find more on sending Twilio SMS messages in the docs.Examples:Load a saved TwilioSMS block and send a message:
from prefect.blocks.notifications import TwilioSMStwilio_webhook_block = TwilioSMS.load("BLOCK_NAME")twilio_webhook_block.notify("Hello from Prefect!")
Enables sending notifications via a provided Opsgenie webhook.
See Apprise notify_opsgenie docs
for more info on formatting the URL.Examples:Load a saved Opsgenie webhook and send a message:
from prefect.blocks.notifications import OpsgenieWebhookopsgenie_webhook_block = OpsgenieWebhook.load("BLOCK_NAME")opsgenie_webhook_block.notify("Hello from Prefect!")
Enables sending notifications via a provided Mattermost webhook.
See Apprise notify_Mattermost docs # noqaExamples:Load a saved Mattermost webhook and send a message:
from prefect.blocks.notifications import MattermostWebhookmattermost_webhook_block = MattermostWebhook.load("BLOCK_NAME")mattermost_webhook_block.notify("Hello from Prefect!")
Enables sending notifications via a provided Discord webhook.
See Apprise notify_Discord docs # noqaExamples:Load a saved Discord webhook and send a message:
from prefect.blocks.notifications import DiscordWebhookdiscord_webhook_block = DiscordWebhook.load("BLOCK_NAME")discord_webhook_block.notify("Hello from Prefect!")
Enables sending notifications via any custom webhook.All nested string param contains {{key}} will be substituted with value from context/secrets.Context values include: subject, body and name.Examples:Load a saved custom webhook and send a message:
from prefect.blocks.notifications import CustomWebhookNotificationBlockcustom_webhook_block = CustomWebhookNotificationBlock.load("BLOCK_NAME")custom_webhook_block.notify("Hello from Prefect!")
Returns a logger based on whether the NotificationBlock
is called from within a flow or task run context.
If a run context is present, the logger property returns a run logger.
Else, it returns a default logger labeled with the class’s name.Returns:
The run logger or a default logger with the class’s name.