Azure Monitor REST API を使用してアクティビティ ログ データを取得する

Azure アクティビティ ログは、サブスクリプションのリソースに対して実行された操作に関する分析情報を提供するログです。 操作には、作成、更新、削除、およびリソースに対して実行されるその他のアクションが含まれます。 アクティビティ ログはプラットフォーム全体のログであり、特定のサービスに限定されません。 この記事では、Azure Monitor REST API を使用してアクティビティ ログ データを取得する方法について説明します。 アクティビティ ログの詳細については、「Azure アクティビティ ログのイベント スキーマ」を参照してください。

認証

リソース ログを取得するには、Microsoft Entra で認証する必要があります。 詳細については、Azure 監視 REST API のチュートリアルをご覧ください。

アクティビティ ログ データの取得

Azure Monitor 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>
  • 関連付け ID のイベントを一覧表示する: $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 引数は、返されるプロパティ名のコンマ区切りのリストです。 有効な値は、authorizationclaimscorrelationIddescriptioneventDataIdeventNameeventTimestamphttpRequestleveloperationIdoperationNamepropertiesresourceGroupNameresourceProviderNameresourceIdstatussubmissionTimestampsubStatussubscriptionId です。

次のサンプル要求では、Azure Monitor REST API を使用し、アクティビティ ログにクエリを実行します。

フィルターを使用してアクティビティ ログを取得します。

次の例では、日付 2023-03-21T20:00:00Z2023-03-24T20:00:00Z の間でリソース グループ MSSupportGroup のアクティビティ ログを取得します

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'

フィルターと選択を使用してアクティビティ ログを取得します。

次の例では、日付 2023-03-21T20:00:00Z2023-03-24T20:00:00Z の間でリソース グループ MSSupportGroup のアクティビティ ログを取得し、要素 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 Monitor アクティビティ ログ データをストリーミングするAzure アクティビティ ログのイベント スキーマ