<@ULVA73B9P> does the open source version of prefe...
# ask-marvin
c
@Marvin does the open source version of prefect allow alerting via teams or slack?
m
thought for 736.3 seconds
n
hi @chase albright marvin is currently preparing an answer to your question above
you shouldnt need to ask the same thing again
but the answer to your question is yes, make an automation
m
Yes. In open-source Prefect (assuming 3.x), you can send alerts to Slack and Microsoft Teams from your flows. What’s available in OSS: - Slack: use either the built-in notification block (
prefect.blocks.notifications.SlackWebhook
) or the
prefect-slack
integration for richer Slack API features. - Docs: Prefect Slack integration - Microsoft Teams: use the built-in
prefect.blocks.notifications.MicrosoftTeamsWebhook
block. - Blocks overview: Blocks in Prefect 3 What’s Cloud-only: - No-code notification policies/automations from the UI are a Prefect Cloud feature. In OSS, you add notifications in code where you want them to fire (e.g., on failures or at the end of a flow). Quick examples - Create and save webhook blocks once:
Copy code
from prefect.blocks.notifications import SlackWebhook, MicrosoftTeamsWebhook

SlackWebhook(url="<https://hooks.slack.com/services/XXX/YYY/ZZZ>").save("my-slack")
MicrosoftTeamsWebhook(url="<https://outlook.office.com/webhook/XXX/YYY/ZZZ>").save("my-teams")
- Use them in a flow:
Copy code
from prefect import flow
from prefect.blocks.notifications import SlackWebhook, MicrosoftTeamsWebhook

@flow
def my_flow():
    slack = SlackWebhook.load("my-slack")
    teams = MicrosoftTeamsWebhook.load("my-teams")

    try:
        # your work here
        ...
        slack.notify("Flow succeeded ✅")
        teams.notify("Flow succeeded ✅")
    except Exception as exc:
        slack.notify(f"Flow failed ❌: {exc}")
        teams.notify(f"Flow failed ❌: {exc}")
        raise
- Alternative Slack option (prefect-slack):
Copy code
# pip install prefect-slack
from prefect import flow
from prefect_slack.messages import send_incoming_webhook_message

@flow
def notify():
    send_incoming_webhook_message(
        webhook_url="<https://hooks.slack.com/services/XXX/YYY/ZZZ>",
        text="Hello from Prefect!"
    )
If you’d like, I can show a pattern to automatically send alerts on any flow failure/success with minimal boilerplate.
c
ok so creating a notofication using hte UI such as on a run-state 'Fail', is not possible in OSS?
n
but the answer to your question is yes, make an automation
> using hte UI i guess the latter is not UI based, but creating an automation is
c
Ok so here is my problem, I was able to set up the webhook, if ran this code from CLI
Copy code
from prefect.blocks.notifications import SlackWebhook

slack_webhook_block = SlackWebhook.load("slack")
slack_webhook_block.notify("Hello from Prefect!")
it runs and triggers no problem, but when i set up throught hte UI, and say trigger an alert on any change in state for testing, it doesnt send any alerts.
n
did you check the event feed or server logs for info on a failed automation execution?
c
yeah there doesnt appear to be any errors int the server or agent, its as if its not triggered at all