在事件网格中订阅“Azure 资源管理”事件
本文介绍订阅“Azure 资源通知 - 资源”发布的事件所需的步骤。 有关这些事件的详细信息,请参阅“Azure 资源通知 - 资源”事件。
本部分介绍如何创建 microsoft.resourcenotifications.resources
类型的系统主题。
将帐户设置为要在其中创建系统主题的 Azure 订阅。
az account set -s AZURESUBSCRIPTIONID
使用 az eventgrid system-topic create
命令创建 microsoft.resourcenotifications.resources
类型的系统主题。
az eventgrid system-topic create \
--name SYSTEMTOPICNAME \
--resource-group RESOURCEGROUPNAME \
--source /subscriptions/AZURESUBSCRIPTIONID \
--topic-type microsoft.resourcenotifications.resources \
--location Global
将帐户设置为要在其中创建系统主题的 Azure 订阅。
Set-AzContext -Subscription AZURESUBSCRIPTIONID
使用 New-AzEventGridSystemTopic 命令创建 microsoft.resourcenotifications.resources
类型的系统主题。
New-AzEventGridSystemTopic -name SYSTEMTOPICNAME `
-resourcegroup RESOURCEGROUPNAME `
-source /subscriptions/AZURESUBSCRIPTIONID `
-topictype microsoft.resourcenotifications.resources `
-location global
登录到 Azure 门户。
在搜索栏中,键入“事件网格系统主题”,然后从下拉列表中选择它。
在“事件网格系统主题”页上的工具栏中,选择“创建”。
在“创建事件网格系统主题”页上,为“主题类型”选择“资源管理事件”。
创建要在其中创建系统主题的资源组。
输入系统主题的名称。
选择“查看 + 创建”
在“查看 + 创建”页面上,选择“创建”。
在“成功部署”页面上选择“转到资源”,导航到你的系统主题所对应的页面。 你会在该页面上看到你的系统主题的详细信息。
使用 az eventgrid system-topic event-subscription create
命令为上述主题创建事件订阅。
以下示例命令为 CreatedOrUpdated 和 Deleted 事件创建事件订阅。 如果未指定 included-event-types
,则默认包含所有事件类型。
az eventgrid system-topic event-subscription create \
--name EVENTSUBSCRIPTIONNAME \
--resource-group RESOURCEGROUPNAME \
--system-topic-name SYSTEMTOPICNAME \
--included-event-types Microsoft.ResourceNotifications.Resources.CreatedOrUpdated, Microsoft.ResourceNotifications.Resources.Deleted \
--endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/MYEVENTHUBSNAMESPACE/eventhubs/MYEVENTHUB \
--endpoint-type eventhub
使用 New-AzEventGridSystemTopicEventSubscription 命令为上述主题创建事件订阅。
以下示例命令为 CreatedOrUpdated 和 Deleted 事件创建事件订阅。 如果未指定 IncludedEventType
,则默认包含所有事件类型。
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName EVENTSUBSCRIPTIONNAME `
-ResourceGroupName RESOURCEGROUPNAME `
-SystemtopicName SYSTEMTOPICNAME `
-IncludedEventType Microsoft.ResourceNotifications.Resources.CreatedOrUpdated, Microsoft.ResourceNotifications.Resources.Deleted `
-Endpoint /subscriptions/AZURESUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/Microsoft.EventHub/namespaces/EVENTHUBSNAMESPACE/eventhubs/EVENTHUB `
-EndpointType eventhub
在“事件网格系统主题”页上的工具栏中,选择“事件订阅”。
确认已自动填充“主题类型”、“源资源”和“主题名称”。
输入事件订阅的名称。
对于“筛选到事件类型”,请选择事件,例如 CreatedOrUpdated 或 Deleted。
选择终结点类型。
基于所选的终结点类型配置事件处理程序。 在以下示例中,选择了 Azure 事件中心。
选择“筛选器”选项卡来提供主题筛选和高级筛选。 例如,若要筛选特定资源组中资源的事件,请执行以下步骤:
选择“启用主题筛选”。
在“主题筛选器”部分,对于“主题开头为”,请按以下格式提供资源组的值:/subscriptions/{subscription-id}/resourceGroups/{resourceGroup-id}
。
然后选择“创建”以创建事件订阅。
若要删除事件订阅,请使用 Remove-AzEventGridSystemTopicEventSubscription
命令。 下面是一个示例:
Remove-AzEventGridSystemTopicEventSubscription -EventSubscriptionName firstEventSubscription -ResourceGroupName sampletestrg -SystemTopicName arnSystemTopicResources
若要删除系统主题,请使用 Remove-AzEventGridSystemTopic
命令。 下面是一个示例:
Remove-AzEventGridSystemTopic -ResourceGroupName sampletestrg -Name arnSystemTopicResources
- 登录到 Azure 门户。
- 在搜索栏中,键入“事件网格系统主题”,然后按 Enter。
- 选择系统主题。
- 在“事件网格系统主题”页上的工具栏中选择“删除”。
在 Azure 订阅中订阅有关虚拟机创建、更新和删除的通知
针对在 Azure 订阅中订阅有关虚拟机创建、更新和删除的通知,本部分显示了筛选示例。
az eventgrid system-topic event-subscription create \
--name firstEventSubscription \
--resource-group sampletestrg \
--system-topic-name arnSystemTopicResources
--included-event-types Microsoft.ResourceNotifications.Resources.CreatedOrUpdated, Microsoft.ResourceNotifications.Resources.Deleted \
--endpoint /subscriptions/000000000-0000-0000-0000-000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources \
--endpoint-type evenhub \
--advanced-filter data.resourceInfo.type StringEndsWith virtualMachines
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName firstEventSubscription `
-ResourceGroupName sampletestrg `
-SystemtopicName arnSystemTopicResources `
-IncludedEventType Microsoft.ResourceNotifications.Resources.CreatedOrUpdated, Microsoft.ResourceNotifications.Resources.Deleted `
-Endpoint /subscriptions/000000000-0000-0000-0000-000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources `
-EndpointType eventhub `
-AdvancedFilter @(@{operator = "StringEndsWith"; key = "data.resourceInfo.type" ; value ="virtualMachines"})
选择 CreatedOrUpdated 和 Deleted 事件类型。
在事件订阅的“筛选器”选项卡中,选择以下高级筛选器。
Key = "data.resourceInfo.type"
Operator = "StringEndsWith"
Value = "virtualMachines"
按特定资源组订阅有关 VM 创建、更新和删除的通知
az eventgrid system-topic event-subscription create \
--name firstEventSubscription \
--resource-group sampletestrg \
--system-topic-name arnSystemTopicResources \
--included-event-types Microsoft.ResourceNotifications.Resources.CreatedOrUpdated, Microsoft.ResourceNotifications.Resources.Deleted \
--endpoint/subscriptions/000000000-0000-0000-0000-0000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources \
--endpoint-type evenhub \
--subject-begins-with /subscription/{Azure subscription ID}/resourceGroups/<Resource group name>/
--advanced-filter data.resourceInfo.type StringEndsWith virtualMachines
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName firstEventSubscription `
-ResourceGroupName sampletestrg `
-SystemtopicName arnSystemTopicResources `
-IncludedEventType Microsoft.ResourceNotifications.Resources.CreatedOrUpdated, Microsoft.ResourceNotifications.Resources.Deleted `
-Endpoint /subscriptions/000000000-0000-0000-0000-000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources `
-EndpointType eventhub -AdvancedFilter @(@{operator = "StringEndsWith"; key = "data.resourceInfo.type" ; value ="virtualMachines"})
在事件订阅的“筛选器”选项卡中,启用主题筛选,并使用以下主题筛选器:
Subject begins with = /subscriptions/{subscription-id}/resourceGroups/{resourceGroup-id}
然后,选择以下高级筛选器。
Key = "data.resourceInfo.type"
Operator = "String ends with"
Value = "virtualMachines"
按订阅中的特定位置订阅有关 VM 创建和更新的通知
az eventgrid system-topic event-subscription create \
--name firstEventSubscription \
--resource-group sampletestrg \
--system-topic-name arnSystemTopicResources \
--included-event-types Microsoft.ResourceNotifications.Resources.CreatedOrUpdated \
--endpoint/subscriptions/000000000-0000-0000-0000-0000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources \
--endpoint-type evenhub \
--subject-begins-with /subscription/{Azure subscription ID}/resourceGroups/<Resource group name>/
--advanced-filter data.resourceInfo.location StringIn chinanorth
--advanced-filter data.resourceInfo.type StringEndsWith virtualMachines
New-AzEventGridSystemTopicEventSubscription -EventSubscriptionName firstEventSubscription `
-ResourceGroupName sampletestrg `
-SystemtopicName arnSystemTopicResources `
-IncludedEventType Microsoft.ResourceNotifications.Resources.CreatedOrUpdated, Microsoft.ResourceNotifications.Resources.Deleted `
-Endpoint /subscriptions/000000000-0000-0000-0000-000000000000/resourceGroups/sampletestrg/providers/Microsoft.EventHub/namespaces/testEventHub/eventhubs/ehforsystemtopicresources `
-EndpointType eventhub `
-AdvancedFilter @(@{operator = "StringIn"; key = "data.resourceInfo.location"; value ="chinanorth"}, @{operator = "StringEndsWith"; key = "data.resourceInfo.type" ; value ="virtualMachines"})
在事件订阅的“筛选器”选项卡中,启用主题筛选,并使用以下主题筛选器:
Subject begins with = /subscriptions/{subscription-id}/resourceGroups/{resourceGroup-id}
然后,选择以下高级筛选器。
Key = "data.resourceInfo.location",
Operator = "String is in"
Value = "chinanorth"
AND
键 = "data.resourceInfo.type",运算符 = "String ends with" 值 = "virtualMachines"
如果对此功能有任何疑问或反馈,请通过 arnsupport@microsoft.com 随时联系我们。
为了更好地帮助你提供有关特定事件的特定反馈,请提供以下信息:
- 系统主题类型名称
- 执行操作时的近似时间戳 (UTC)
- 为其生成通知的基本资源 ID
- 在 Azure 门户中导航到你的资源,然后选择最右侧的 JSON 视图。 资源 ID 是 JSON 视图页上的第一个字段。
- 预期的事件类型
- 执行的操作(例如 VM 已启动或停止、已创建存储帐户等)
- 遇到的问题的说明(例如,VM 已启动,但未生成 Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged 事件)
- 如果可能,请提供所执行的操作的相关 ID
- 系统主题类型名称
- 不包括 data.resourceInfo.properties 的通知的全部内容
- 遇到的问题的说明和受影响的字段值
请确保在共享此数据时未提供任何最终用户身份信息。
有关这些事件的详细信息,请参阅“Azure 资源通知 - 资源”事件。