Sirivella Zephaniah Greetings!
I want to create an alert rule which will send an email notification when a specific pipeline fails.
To create an alert rule that sends an email notification when a specific pipeline fails, you can follow these steps:
Azure Portal:
- Go to the Azure portal and navigate to your Machine Learning workspace.
- Click on the "Alerts" tab in the left-hand menu.
- Click on the "New alert rule" button.
- In the "Create alert rule" pane, select the "Metric alert" option. select your Machine Learning workspace and the "Pipelines" resource type.
- In the "Actions" section, select the "Email" option and enter the email address(es) you want to receive the notification.
- Click on the "Create alert rule" button to create the alert rule.
Using Python SDK :
To create an alert rule that sends an email notification when a specific pipeline fails using Python SDK, you can use the azure.mgmt.monitor
package. Here is an example code snippet that creates an alert rule to send an email notification when a specific pipeline fails:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.monitor import MonitorManagementClient
from azure.mgmt.monitor.models import *
# Replace with your own subscription ID, resource group name, and pipeline name
subscription_id = '<subscription_id>'
resource_group_name = '<resource_group_name>'
workspace_name = '<workspace_name>'
pipeline_name = '<pipeline_name>'
# Replace with your own tenant ID, client ID, and client secret
tenant_id = '<tenant_id>'
client_id = '<client_id>'
client_secret = '<client_secret>'
# Authenticate with Azure using a service principal
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=client_secret,
tenant=tenant_id
)
# Create a MonitorManagementClient object
monitor_client = MonitorManagementClient(
credentials=credentials,
subscription_id=subscription_id
)
# Define the alert rule criteria
criteria = MetricAlertCriteria(
name='PipelineRunStatus',
metric_namespace='Microsoft.MachineLearningServices/workspaces/pipelines',
dimensions=[
MetricDimension(
name='PipelineName',
value=pipeline_name
),
MetricDimension(
name='Status',
value='Failed'
)
],
metric_name='PipelineRunStatus',
operator='GreaterThan',
threshold='0',
time_aggregation='Count',
time_grain='PT5M'
)
# Define the alert rule action
action = AlertRuleAction(
send_email_to_subscription_administrator=True,
custom_emails=['<email_address>']
)
# Create the alert rule object
alert_rule = AlertRule(
location='global',
alert_rule_resource_id=f'/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}',
description='Alert rule for failed pipeline runs',
criteria=criteria,
actions=[action]
)
# Create the alert rule
monitor_client.alert_rules.create_or_update(
resource_group_name=resource_group_name,
rule_name='FailedPipelineRuns',
parameters=alert_rule
)
I would suggest you, please check the below documentation as well for more details.
Monitor Azure Machine Learning
Troubleshooting machine learning pipelines
How to use pipeline UI to debug Azure Machine Learning pipeline failures
Microsoft Azure SDK for Python
Do let me know if that helps or have any other queries.
If the response helped, please do click Accept Answer
and Yes
for was this answer helpful.