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=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
引数は、返されるプロパティ名のコンマ区切りのリストです。
有効な値は、 authorization
、 claims
、 correlationId
、 description
、 eventDataId
、 eventName
、 eventTimestamp
、 httpRequest
、 level
、 operationId
operationName
、 properties
、 resourceGroupName
、 resourceProviderName
、 resourceId
、 status
、 submissionTimestamp
、 subStatus
、および subscriptionId
です。
次のサンプル要求では、Azure Monitor 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
のアクティビティ ログを取得し、要素 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
次のステップ
Azure Monitor アクティビティ ログ データをストリーミングします。 Azure アクティビティ ログのイベント スキーマ。