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=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、claims、correlationId、description、eventDataId、eventName、eventTimestamp、httpRequest、level、operationId、operationName、properties、resourceGroupName、resourceProviderName、resourceId、status、submissionTimestamp、subStatus和subscriptionId。
下列範例要求會使用 Azure 監視器 REST API 來查詢活動記錄。
使用篩選來取得活動記錄:
下列範例會取得資源群組MSSupportGroup在日期2023-03-21T20:00:00Z與2023-03-24T20:00:00Z之間的活動記錄
GET https://management.azure.com/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/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:00Z 和 2023-03-24T20:00:00Z之間,傳回 elements eventName、operationName、status、eventTimestamp、correlationId、submissionTimestamp 和 level。
GET https://management.azure.com/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/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