Microsoft Azure Monitor Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Action groups define a collection of notification preferences and automated actions that are triggered when Azure Monitor alerts are fired. They support multiple notification channels including email, SMS, webhooks, Azure Functions, Logic Apps, and integration with ITSM systems.
Create, update, delete, and retrieve action groups with comprehensive notification configurations.
def create_or_update(resource_group_name: str, action_group_name: str, action_group: ActionGroupResource, **kwargs: Any) -> ActionGroupResource:
"""
Create a new action group or update an existing one.
Parameters:
- resource_group_name: str - Name of the resource group
- action_group_name: str - Name of the action group
- action_group: ActionGroupResource - Action group configuration
Returns:
ActionGroupResource - The created or updated action group
"""
def get(resource_group_name: str, action_group_name: str, **kwargs: Any) -> ActionGroupResource:
"""
Get an action group by name.
Parameters:
- resource_group_name: str - Name of the resource group
- action_group_name: str - Name of the action group
Returns:
ActionGroupResource - The action group details
"""
def delete(resource_group_name: str, action_group_name: str, **kwargs: Any) -> None:
"""
Delete an action group.
Parameters:
- resource_group_name: str - Name of the resource group
- action_group_name: str - Name of the action group
"""
def update(resource_group_name: str, action_group_name: str, action_group_patch: ActionGroupPatchBody, **kwargs: Any) -> ActionGroupResource:
"""
Update an existing action group's tags and properties.
Parameters:
- resource_group_name: str - Name of the resource group
- action_group_name: str - Name of the action group
- action_group_patch: ActionGroupPatchBody - Properties to update
Returns:
ActionGroupResource - The updated action group
"""List action groups within subscriptions and resource groups with pagination support.
def list_by_subscription_id(**kwargs: Any) -> ItemPaged[ActionGroupResource]:
"""
Get a list of all action groups in a subscription.
Returns:
ItemPaged[ActionGroupResource] - Paginated list of action groups
"""
def list_by_resource_group(resource_group_name: str, **kwargs: Any) -> ItemPaged[ActionGroupResource]:
"""
Get a list of all action groups in a resource group.
Parameters:
- resource_group_name: str - Name of the resource group
Returns:
ItemPaged[ActionGroupResource] - Paginated list of action groups
"""Enable and disable specific receivers within action groups, supporting email and SMS receivers.
def enable_receiver(resource_group_name: str, action_group_name: str, enable_request: EnableRequest, **kwargs: Any) -> None:
"""
Enable a receiver in an action group (Email or SMS receivers only).
Parameters:
- resource_group_name: str - Name of the resource group
- action_group_name: str - Name of the action group
- enable_request: EnableRequest - Request to enable receiver
"""Send test notifications to validate action group configurations and retrieve test results.
def begin_create_notifications_at_action_group_resource_level(resource_group_name: str, action_group_name: str, notification_request: NotificationRequestBody, **kwargs: Any) -> LROPoller[TestNotificationDetailsResponse]:
"""
Send test notifications to a set of provided receivers.
Parameters:
- resource_group_name: str - Name of the resource group
- action_group_name: str - Name of the action group
- notification_request: NotificationRequestBody - Test notification configuration
Returns:
LROPoller[TestNotificationDetailsResponse] - Long-running operation poller
"""
def get_test_notifications_at_action_group_resource_level(resource_group_name: str, action_group_name: str, notification_id: str, **kwargs: Any) -> TestNotificationDetailsResponse:
"""
Get the test notifications by the notification id.
Parameters:
- resource_group_name: str - Name of the resource group
- action_group_name: str - Name of the action group
- notification_id: str - Notification identifier
Returns:
TestNotificationDetailsResponse - Test notification results
"""from azure.mgmt.monitor.models import (
ActionGroupResource, EmailReceiver, SmsReceiver,
WebhookReceiver, ReceiverStatus
)
# Define receivers
email_receivers = [
EmailReceiver(
name="admin-email",
email_address="admin@example.com",
use_common_alert_schema=True
)
]
sms_receivers = [
SmsReceiver(
name="admin-sms",
country_code="1",
phone_number="5551234567"
)
]
webhook_receivers = [
WebhookReceiver(
name="webhook-notification",
service_uri="https://example.com/webhook",
use_common_alert_schema=True
)
]
# Create action group
action_group = ActionGroupResource(
location="global",
group_short_name="AdminAlerts",
enabled=True,
email_receivers=email_receivers,
sms_receivers=sms_receivers,
webhook_receivers=webhook_receivers
)
# Create the action group
result = client.action_groups.create_or_update(
resource_group_name="monitoring-rg",
action_group_name="admin-action-group",
action_group=action_group
)from azure.mgmt.monitor.models import NotificationRequestBody
# Prepare test notification request
test_request = NotificationRequestBody(
alert_type="servicehealth",
email_receivers=["admin@example.com"],
sms_receivers=[{"country_code": "1", "phone_number": "5551234567"}]
)
# Send test notifications
test_operation = client.action_groups.begin_create_notifications_at_action_group_resource_level(
resource_group_name="monitoring-rg",
action_group_name="admin-action-group",
notification_request=test_request
)
# Wait for completion and get results
test_result = test_operation.result()
print(f"Test notification status: {test_result.state}")class ActionGroupResource:
"""Action group resource definition."""
location: str # Resource location (typically "global")
group_short_name: str # Short name for SMS notifications (max 12 chars)
enabled: bool # Whether the action group is enabled
email_receivers: Optional[List[EmailReceiver]] # Email notification receivers
sms_receivers: Optional[List[SmsReceiver]] # SMS notification receivers
webhook_receivers: Optional[List[WebhookReceiver]] # Webhook receivers
itsm_receivers: Optional[List[ItsmReceiver]] # ITSM system receivers
azure_app_push_receivers: Optional[List[AzureAppPushReceiver]] # Azure app push receivers
automation_runbook_receivers: Optional[List[AutomationRunbookReceiver]] # Automation runbook receivers
voice_receivers: Optional[List[VoiceReceiver]] # Voice call receivers
logic_app_receivers: Optional[List[LogicAppReceiver]] # Logic App receivers
azure_function_receivers: Optional[List[AzureFunctionReceiver]] # Azure Function receivers
arm_role_receivers: Optional[List[ArmRoleReceiver]] # ARM role-based receivers
event_hub_receivers: Optional[List[EventHubReceiver]] # Event Hub receivers
class EmailReceiver:
"""Email notification receiver."""
name: str # Receiver name
email_address: str # Email address
use_common_alert_schema: Optional[bool] # Use common alert schema format
status: Optional[ReceiverStatus] # Receiver status
class SmsReceiver:
"""SMS notification receiver."""
name: str # Receiver name
country_code: str # Country code (e.g., "1" for US)
phone_number: str # Phone number
status: Optional[ReceiverStatus] # Receiver status
class WebhookReceiver:
"""Webhook notification receiver."""
name: str # Receiver name
service_uri: str # Webhook URL
use_common_alert_schema: Optional[bool] # Use common alert schema format
use_aad_auth: Optional[bool] # Use Azure AD authentication
object_id: Optional[str] # Azure AD object ID for authentication
identifier_uri: Optional[str] # Azure AD identifier URI
tenant_id: Optional[str] # Azure AD tenant ID
class ActionGroupPatchBody:
"""Action group patch request body."""
tags: Optional[Dict[str, str]] # Resource tags
enabled: Optional[bool] # Whether action group is enabled
class EnableRequest:
"""Request to enable a receiver."""
receiver_name: str # Name of receiver to enable
class NotificationRequestBody:
"""Test notification request body."""
alert_type: str # Type of alert (e.g., "servicehealth", "metricAlert")
email_receivers: Optional[List[str]] # Email addresses for testing
sms_receivers: Optional[List[Dict[str, str]]] # SMS receivers for testing
webhook_receivers: Optional[List[Dict[str, str]]] # Webhook receivers for testing
class TestNotificationDetailsResponse:
"""Test notification results."""
notification_id: Optional[str] # Notification identifier
state: Optional[str] # Notification state
completed_time: Optional[str] # Completion timestamp
created_time: Optional[str] # Creation timestamp
action_details: Optional[List[ActionDetail]] # Detailed results per receiver
ReceiverStatus = Union["Enabled", "Disabled", "NotSpecified"] # Receiver status valuesInstall with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-monitor