使用 Azure 監視器 REST API 擷取活動記錄數據

Azure 活動記錄是一個記錄,可讓您深入瞭解訂用帳戶中資源上執行的作業。 作業包括建立、更新、刪除和其他對資源採取的動作。 活動記錄是全平台的記錄,不限於特定服務。 本文說明如何使用 Azure 監視器 REST API 擷取活動記錄數據。 如需活動記錄的詳細資訊,請參閱 Azure 活動記錄事件架構

驗證

若要擷取資源記錄,您必須向 Microsoft Entra 進行驗證。 如需詳細資訊,請參閱 Azure 監視 REST API 逐步解說

擷取活動記錄數據

使用 Azure 監視器 REST API 來查詢 活動記錄 數據。

下列要求格式是用來要求活動記錄數據。

GET /subscriptions/<subscriptionId>/providers/Microsoft.Insights/eventtypes/management/values \
?api-version=2015-04-01 \
&$filter=<filter> \
&$select=<select>
host: management.azure.com
authorization: Bearer <token>

$filter

$filter 會減少收集的數據集。 此自變數是必要的,而且至少需要開始日期/時間。 自 $filter 變數接受下列模式:

  • 列出資源群組的事件: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceGroupName eq <resourceGroupName>
  • 列出特定資源的事件: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceUri eq <resourceURI>
  • 列出時間範圍內的訂用帳戶事件: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z'
  • 列出資源提供者的事件: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceProvider eq <resourceProviderName>
  • 列出相互關聯標識碼的事件: $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and correlationId eq '<correlationID>

$select

$select 擷取所傳回事件的指定屬性清單。 自 $select 變數是要傳回之屬性名稱的逗號分隔清單。 有效值為:authorization、、、submissionTimestamppropertiesclaimseventTimestampdescriptioneventDataIdhttpRequesteventNamelevelcorrelationIdresourceGroupNameoperationNameresourceProviderNameoperationIdstatusresourceIdsubStatus和 。subscriptionId

下列範例要求會使用 Azure 監視器 REST API 來查詢活動記錄。

使用篩選來取得活動記錄:

下列範例會取得日期2023-03-21T20:00:00Z與之間資源群組MSSupportGroup的活動記錄2023-03-24T20:00:00Z

GET https://management.azure.com/subscriptions/12345678-abcd-98765432-abcdef012345/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp ge '2023-03-21T20:00:00Z' and eventTimestamp le '2023-03-24T20:00:00Z' and resourceGroupName eq 'MSSupportGroup'

使用篩選取得活動記錄,然後選取:

下列範例會取得資源群組 MSSupportGroup的活動記錄,介於 日期 2023-03-21T20:00:00Z2023-03-24T20:00:00Z之間,傳回 elements eventName、operationName、status、eventTimestamp、correlationId、submissionTimestamp 和 level。

GET https://management.azure.com/subscriptions/12345678-abcd-98765432-abcdef012345/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp ge '2023-03-21T20:00:00Z' and eventTimestamp le '2023-03-24T20:00:00Z'and resourceGroupName eq 'MSSupportGroup'&$select=eventName,operationName,status,eventTimestamp,correlationId,submissionTimestamp,level

下一步

串流 Azure 監視器活動記錄數據Azure 活動記錄事件架構