Share via


訂閱事件方格中的 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 命令來建立上述主題的事件訂閱。

下列範例命令會為 CreatedOrUpdatedDeleted 事件建立事件訂閱。 如果您未指定 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 的近似時間戳記
  • 產生通知的基底資源識別碼
  • 在 Azure 入口網站中瀏覽至您的資源,然後選取最右側的 JSON 檢視。 資源識別碼是 JSON 檢視頁面上的第一個欄位。
  • 預期的事件類型
  • 執行的作業 (例如 VM 已啟動或停止、已建立記憶體帳戶等)
  • 發生問題的描述 (例如,VM 已啟動,且未產生 Microsoft.ResourceNotifications.HealthResources.AvailabilityStatusChanged 事件)
  • 可能的話,請提供所執行作業的相互關聯識別碼

針對延遲或有非預期內容的事件

  • 系統主題類型名稱
  • 通知的整個內容 (排除 data.resourceInfo.properties)
  • 所遇到問題的描述和受影響欄位的值

請確定您在共用此資料時,未提供任何終端使用者可識別的資訊。

下一步

如需關於這些事件的詳細資訊,請參閱 Azure 資源通知 - 資源事件