<@ULVA73B9P> is it possible to use Prefect's autom...
# ask-marvin
r
@Marvin is it possible to use Prefect's automation to : 1. Audit all runs, all deployment changes 2. Report flow failures into MS Teams ?
m
thought for 1001.9 seconds
thought for 455.2 seconds
Short answer: Yes. A bit more detail: - Auditing runs and deployment changes: In Prefect Cloud (3.x), Automations can listen to events (e.g., flow-run state changes, deployment created/updated/deleted) and take actions. You can create Automations that: - Capture all flow run state changes (or just failures) and send a notification - Capture deployment lifecycle changes (created/updated/deleted) and send a notification - Reporting failures to Microsoft Teams: Create a Microsoft Teams notification destination (via an Incoming Webhook URL in your Teams channel), then add an Automation with trigger “Flow run state enters Failed” and action “Send notification” to your Teams destination. Typical setup (Cloud UI): 1) Add a Teams notification destination: - In Microsoft Teams, create an Incoming Webhook for the target channel and copy the URL. - In Prefect Cloud, go to Settings > Notifications > Destinations > Add Destination > Microsoft Teams and paste the webhook URL. 2) Create Automations: - Flow failures to Teams: - Trigger: Flow run state enters Failed - Action: Send notification to your Teams destination - Deployment changes to Teams: - Trigger: Deployment created/updated/deleted (you can choose one or all three) - Action: Send notification to your Teams destination - Optional “audit everything”: - Trigger: Flow run state enters Any state (or a set of states like Scheduled/Running/Completed/Failed) to get a stream of all run activity - Action: Send notification (consider rate-limiting/noise) Notes and caveats: - Cloud vs OSS: These Automations and Notification Destinations are Prefect Cloud features. If you’re self-hosting (OSS), you won’t have the same built-in notifications UI; you’d typically forward events to your own webhook/service or handle notifications in your flow code. - Volume: Auditing “all runs” can be noisy. Many teams narrow to interesting transitions (e.g., Failed, Crashed) or route full audit streams to a webhook/SIEM and only send Teams alerts for errors. Helpful reads: - Automations overview and examples: Chaining deployments with events (Automations how-to) - Background on Prefect events/automations: Expect the unexpected: Automations and observability - If you need formal user/resource audit logs (beyond run/deployment events): Audit logs in Prefect Cloud Questions to tailor this for you: - Are you using Prefect Cloud or self-hosted Prefect? - Do you want Teams notifications for all run state changes, or just failures? - For deployment “audits,” do you want created/updated/deleted, or only certain changes?
1
Short answer: yes. In Prefect 3.x you can use Automations and the Events system to audit: - All flow runs: Create an Automation with an Event trigger that matches all flow-run events (e.g., match on resource type = flow-run). Send the full event payload to a webhook, Slack, or email for your audit sink. - Deployment changes: Create a Deployment Event trigger for create/update/delete events on deployments and route those events to your audit sink as well. Common ways to implement this: - UI: Automations → New automation - Trigger: Event → match resource type = flow run → posture Reactive → Action: Call webhook (or Send notification) to forward each event. - Trigger: Deployment event → choose Created/Updated/Deleted → Action: Call webhook (or Send notification). - API: Use the Automations REST endpoint to create Event/DeploymentEvent triggers and attach CallWebhook/SendNotification actions. See API refs below. If you need a durable, centralized audit trail: - Use an Automation with a webhook action to ship every matching event payload to your logging/SIEM (e.g., Splunk, Datadog, S3). - Or subscribe to the Events feed and persist it yourself; you can also emit custom events from flows if needed. Additional auditing in Prefect Cloud: - Prefect Cloud provides account-level audit logs (user sign-ins, API keys, invites, etc.) for security/compliance. This is separate from run/deployment events and complements your automation-based event capture. - Docs: Cloud audit logs Helpful references: - Create Automations via API: Create automation API - Example of event-driven automations: Chaining deployments with events - Events and automation types in code (what triggers/actions exist): prefect.events Python API Quick CLI you can use today (manage, not create): - List automations
Copy code
prefect automation ls
- Inspect an automation
Copy code
prefect automation inspect "<name>"
- Pause/Resume
Copy code
prefect automation pause "<name>"
  prefect automation resume "<name>"
A couple of clarifying questions so I can share exact steps or example payloads: - Are you on Prefect Cloud or self-hosted? - Do you want these audit events forwarded to Slack, a generic webhook, or another system (e.g., S3/Datadog/Splunk)? - For flow runs, do you want every state transition or just failures? And for deployments, do you want just create/update/delete or all changes?