你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在事件网格中订阅“Azure 资源管理”事件(预览)

本文介绍订阅“Azure 资源通知 - 资源”发布的事件所需的步骤。 有关这些事件的详细信息,请参阅“Azure 资源通知 - 资源”事件

创建“资源”系统主题

本部分介绍如何创建 microsoft.resourcenotifications.resources 类型的系统主题。

  1. 将帐户设置为要在其中创建系统主题的 Azure 订阅。

    az account set –s AZURESUBSCRIPTIONID
    
  2. 使用 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        
    

订阅活动

使用 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        

删除事件订阅和系统主题

若要删除事件订阅,请使用 az eventgrid system-topic event-subscription delete 命令。 下面是一个示例:

az eventgrid system-topic event-subscription delete --name firstEventSubscription --resourcegroup sampletestrg --system-topic-name arnSystemTopicResources

若要删除系统主题,请使用 az eventgrid system-topic delete 命令。 下面是一个示例:

az eventgrid system-topic delete --name arnSystemTopicResources --resource-group sampletestrg

筛选示例

在 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

按特定资源组订阅有关 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

按订阅中的特定位置订阅有关 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 eastus 
    –-advanced-filter data.resourceInfo.type StringEndsWith virtualMachines

联系我们

如果对此功能有任何疑问或反馈,请通过 arnsupport@microsoft.com 随时联系我们。

为了更好地帮助你提供有关特定事件的特定反馈,请提供以下信息:

对于丢失的事件:

  • 系统主题类型名称
  • 执行操作时的近似时间戳 (UTC)
  • 为其生成通知的基本资源 ID
  • 在 Azure 门户中导航到你的资源,然后选择最右侧的 JSON 视图。 资源 ID 是 JSON 视图页上的第一个字段。
  • 预期的事件类型
  • 执行的操作(例如 VM 已启动或停止、已创建存储帐户等)
  • 遇到的问题的说明(例如,VM 已启动,但未生成 Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged 事件)
  • 如果可能,请提供所执行的操作的相关 ID

对于延迟或具有意外内容的事件

  • 系统主题类型名称
  • 不包括 data.resourceInfo.properties 的通知的全部内容
  • 遇到的问题的说明和受影响的字段值

请确保在共享此数据时未提供任何最终用户身份信息。

后续步骤

有关这些事件的详细信息,请参阅“Azure 资源通知 - 资源”事件