Event Grid 원본으로서의 Azure 리소스 그룹

이 문서에서는 리소스 그룹 이벤트에 대한 속성 및 스키마를 제공합니다. 이벤트 스키마에 대한 소개는 Azure Event Grid 이벤트 스키마를 참조하세요.

Azure 구독 및 리소스 그룹은 동일한 이벤트 유형을 내보냅니다. 이벤트 유형은 리소스 변경 또는 작업과 관련이 있습니다. 주요 차이는 리소스 그룹이 리소스 그룹 내 리소스에 대한 이벤트를 내보내고 Azure 구독은 구독 전체에서 리소스에 대한 이벤트를 내보낸다는 것입니다.

management.azure.com로 전송되는 PUT, PATCH, POST 및 DELETE 작업에 대한 리소스 이벤트가 만들어집니다. GET 작업은 이벤트를 만들지 않습니다. 데이터 평면으로 전송된 작업(예: myaccount.blob.core.windows.net)은 이벤트를 만들지 않습니다. 작업 이벤트는 리소스에 대한 키 나열 같은 작업의 이벤트 데이터를 제공합니다.

리소스 그룹에 대한 이벤트를 구독하면 엔드포인트는 해당 리소스 그룹에 대한 모든 이벤트를 받습니다. 이벤트에는 가상 머신 업데이트와 같이 확인하려는 이벤트뿐만 아니라 배포 기록에 새 항목을 작성하는 것과 같이 중요하지 않은 이벤트도 포함될 수 있습니다. 엔드포인트에서 모든 이벤트를 수신하고, 처리하려는 이벤트를 처리하는 코드를 작성할 수 있습니다. 또는 이벤트 구독을 만들 때 필터를 설정할 수 있습니다.

프로그래밍 방식으로 이벤트를 처리하려면 operationName 값을 검토해 이벤트를 정렬할 수 있습니다. 예를 들어 이벤트 엔드포인트는 Microsoft.Compute/virtualMachines/write 또는 Microsoft.Storage/storageAccounts/write와 동일한 작업에 대한 이벤트만 처리할 수 있습니다.

이벤트 주체는 작업의 대상이 되는 리소스의 리소스 ID입니다. 리소스에 대한 이벤트를 필터링하려면 이벤트 구독을 만들 때 해당 리소스 ID를 제공합니다. 리소스 종류별로 필터링하려면 /subscriptions/<subscription-id>/resourcegroups/<resource-group>/providers/Microsoft.Compute/virtualMachines과 같은 형식으로 값을 사용합니다.

사용할 수 있는 이벤트 유형

VM을 만들거나 스토리지 계정을 삭제할 때와 같이 리소스 그룹은 Azure Resource Manager에서 관리 이벤트를 내보냅니다.

이벤트 유형 설명
Microsoft.Resources.ResourceActionCancel 리소스에서 작업이 취소되면 발생합니다.
Microsoft.Resources.ResourceActionFailure 리소스에서 작업이 실패하면 발생합니다.
Microsoft.Resources.ResourceActionSuccess 리소스에서 작업이 성공하면 발생합니다.
Microsoft.Resources.ResourceDeleteCancel 삭제 작업이 취소되면 발생합니다. 이 이벤트는 템플릿 배포가 취소될 때 발생합니다.
Microsoft.Resources.ResourceDeleteFailure 삭제 작업이 실패하면 발생합니다.
Microsoft.Resources.ResourceDeleteSuccess 삭제 작업이 성공하면 발생합니다.
Microsoft.Resources.ResourceWriteCancel 만들기 또는 업데이트 작업이 취소되면 발생합니다.
Microsoft.Resources.ResourceWriteFailure 만들기 또는 업데이트 작업이 실패하면 발생합니다.
Microsoft.Resources.ResourceWriteSuccess 만들기 또는 업데이트 작업이 성공하면 발생합니다.

예제 이벤트

다음 예제는 ResourceWriteSuccess 이벤트의 스키마를 보여줍니다. 동일한 스키마가 eventType에 대한 다른 값을 사용하여 ResourceWriteFailureResourceWriteCancel 이벤트에 사용됩니다.

[{
  "subject": "/subscriptions/{subscription-id}/resourcegroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-name}",
  "source": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}",
  "type": "Microsoft.Resources.ResourceWriteSuccess",
  "time": "2018-07-19T18:38:04.6117357Z",
  "id": "4db48cba-50a2-455a-93b4-de41a3b5b7f6",
  "data": {
    "authorization": {
      "scope": "/subscriptions/{subscription-id}/resourcegroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-name}",
      "action": "Microsoft.Storage/storageAccounts/write",
      "evidence": {
        "role": "Subscription Admin"
      }
    },
    "claims": {
      "aud": "{audience-claim}",
      "iss": "{issuer-claim}",
      "iat": "{issued-at-claim}",
      "nbf": "{not-before-claim}",
      "exp": "{expiration-claim}",
      "_claim_names": "{\"groups\":\"src1\"}",
      "_claim_sources": "{\"src1\":{\"endpoint\":\"{URI}\"}}",
      "http://schemas.microsoft.com/claims/authnclassreference": "1",
      "aio": "{token}",
      "http://schemas.microsoft.com/claims/authnmethodsreferences": "rsa,mfa",
      "appid": "{ID}",
      "appidacr": "2",
      "http://schemas.microsoft.com/2012/01/devicecontext/claims/identifier": "{ID}",
      "e_exp": "{expiration}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname": "{last-name}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname": "{first-name}",
      "ipaddr": "{IP-address}",
      "name": "{full-name}",
      "http://schemas.microsoft.com/identity/claims/objectidentifier": "{ID}",
      "onprem_sid": "{ID}",
      "puid": "{ID}",
      "http://schemas.microsoft.com/identity/claims/scope": "user_impersonation",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "{ID}",
      "http://schemas.microsoft.com/identity/claims/tenantid": "{ID}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "{user-name}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn": "{user-name}",
      "uti": "{ID}",
      "ver": "1.0"
    },
    "correlationId": "{ID}",
    "resourceProvider": "Microsoft.Storage",
    "resourceUri": "/subscriptions/{subscription-id}/resourcegroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-name}",
    "operationName": "Microsoft.Storage/storageAccounts/write",
    "status": "Succeeded",
    "subscriptionId": "{subscription-id}",
    "tenantId": "{tenant-id}"
  },

  "specversion": "1.0"
}]

다음 예제는 ResourceDeleteSuccess 이벤트의 스키마를 보여줍니다. 동일한 스키마가 eventType에 대한 다른 값을 사용하여 ResourceDeleteFailureResourceDeleteCancel 이벤트에 사용됩니다.

[{
  "subject": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-name}",
  "source": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}",
  "type": "Microsoft.Resources.ResourceDeleteSuccess",
  "time": "2018-07-19T19:24:12.763881Z",
  "id": "19a69642-1aad-4a96-a5ab-8d05494513ce",
  "data": {
    "authorization": {
      "scope": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-name}",
      "action": "Microsoft.Storage/storageAccounts/delete",
      "evidence": {
        "role": "Subscription Admin"
      }
    },
    "claims": {
      "aud": "{audience-claim}",
      "iss": "{issuer-claim}",
      "iat": "{issued-at-claim}",
      "nbf": "{not-before-claim}",
      "exp": "{expiration-claim}",
      "_claim_names": "{\"groups\":\"src1\"}",
      "_claim_sources": "{\"src1\":{\"endpoint\":\"{URI}\"}}",
      "http://schemas.microsoft.com/claims/authnclassreference": "1",
      "aio": "{token}",
      "http://schemas.microsoft.com/claims/authnmethodsreferences": "rsa,mfa",
      "appid": "{ID}",
      "appidacr": "2",
      "http://schemas.microsoft.com/2012/01/devicecontext/claims/identifier": "{ID}",
      "e_exp": "262800",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname": "{last-name}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname": "{first-name}",
      "ipaddr": "{IP-address}",
      "name": "{full-name}",
      "http://schemas.microsoft.com/identity/claims/objectidentifier": "{ID}",
      "onprem_sid": "{ID}",
      "puid": "{ID}",
      "http://schemas.microsoft.com/identity/claims/scope": "user_impersonation",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "{ID}",
      "http://schemas.microsoft.com/identity/claims/tenantid": "{ID}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "{user-name}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn": "{user-name}",
      "uti": "{ID}",
      "ver": "1.0"
    },
    "correlationId": "{ID}",
    "httpRequest": {
      "clientRequestId": "{ID}",
      "clientIpAddress": "{IP-address}",
      "method": "DELETE",
      "url": "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-name}?api-version=2018-02-01"
    },
    "resourceProvider": "Microsoft.Storage",
    "resourceUri": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-name}",
    "operationName": "Microsoft.Storage/storageAccounts/delete",
    "status": "Succeeded",
    "subscriptionId": "{subscription-id}",
    "tenantId": "{tenant-id}"
  },
  "specversion": "1.0"
}]

다음 예제는 ResourceActionSuccess 이벤트의 스키마를 보여줍니다. 동일한 스키마가 eventType에 대한 다른 값을 사용하여 ResourceActionFailureResourceActionCancel 이벤트에 사용됩니다.

[{   
  "subject": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventHub/namespaces/{namespace}/AuthorizationRules/RootManageSharedAccessKey",
  "source": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}",
  "type": "Microsoft.Resources.ResourceActionSuccess",
  "time": "2018-10-08T22:46:22.6022559Z",
  "id": "{ID}",
  "data": {
    "authorization": {
      "scope": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventHub/namespaces/{namespace}/AuthorizationRules/RootManageSharedAccessKey",
      "action": "Microsoft.EventHub/namespaces/AuthorizationRules/listKeys/action",
      "evidence": {
        "role": "Contributor",
        "roleAssignmentScope": "/subscriptions/{subscription-id}",
        "roleAssignmentId": "{ID}",
        "roleDefinitionId": "{ID}",
        "principalId": "{ID}",
        "principalType": "ServicePrincipal"
      }     
    },
    "claims": {
      "aud": "{audience-claim}",
      "iss": "{issuer-claim}",
      "iat": "{issued-at-claim}",
      "nbf": "{not-before-claim}",
      "exp": "{expiration-claim}",
      "aio": "{token}",
      "appid": "{ID}",
      "appidacr": "2",
      "http://schemas.microsoft.com/identity/claims/identityprovider": "{URL}",
      "http://schemas.microsoft.com/identity/claims/objectidentifier": "{ID}",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "{ID}",       "http://schemas.microsoft.com/identity/claims/tenantid": "{ID}",
      "uti": "{ID}",
      "ver": "1.0"
    },
    "correlationId": "{ID}",
    "httpRequest": {
      "clientRequestId": "{ID}",
      "clientIpAddress": "{IP-address}",
      "method": "POST",
      "url": "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventHub/namespaces/{namespace}/AuthorizationRules/RootManageSharedAccessKey/listKeys?api-version=2017-04-01"
    },
    "resourceProvider": "Microsoft.EventHub",
    "resourceUri": "/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventHub/namespaces/{namespace}/AuthorizationRules/RootManageSharedAccessKey",
    "operationName": "Microsoft.EventHub/namespaces/AuthorizationRules/listKeys/action",
    "status": "Succeeded",
    "subscriptionId": "{subscription-id}",
    "tenantId": "{tenant-id}"
  },
  "specversion": "1.0"
}]

이벤트 속성

이벤트에는 다음과 같은 최상위 데이터가 있습니다.

속성 Type Description
source string 이벤트 원본에 대한 전체 리소스 경로입니다. 이 필드는 쓸 수 없습니다. Event Grid는 이 값을 제공합니다.
subject string 게시자가 정의한 이벤트 주체의 경로입니다.
type string 이 이벤트 원본에 대해 등록된 이벤트 유형 중 하나입니다.
time string 공급자의 UTC 시간을 기준으로 이벤트가 생성되는 시간입니다.
id string 이벤트에 대한 고유 식별자입니다.
data 개체 리소스 그룹 이벤트 데이터입니다.
specversion string CloudEvents 스키마 사양 버전입니다.

데이터 개체의 속성은 다음과 같습니다.

속성 Type 설명
authorization 개체 작업에 대해 요청된 권한입니다.
claims 개체 클레임의 속성입니다. 자세한 내용은 JWT 사양을 참조하세요.
correlationId string 문제 해결을 위한 작업 ID입니다.
httpRequest 개체 작업의 세부 정보입니다. 이 개체는 기존 리소스를 업데이트하거나 리소스를 삭제하는 경우에만 포함됩니다.
resourceProvider string 작업에 대한 리소스 공급자입니다.
resourceUri string 작업에서 리소스의 URI입니다.
operationName string 수행된 작업입니다.
status string 작업의 상태입니다.
subscriptionId string 리소스의 구독 ID입니다.
tenantId string 리소스의 테넌트 ID입니다.

자습서 및 방법

제목 설명
자습서: Azure Event Grid 및 Logic Apps를 사용하여 가상 머신 변경 내용 모니터링 논리 앱은 가상 머신의 변경 내용을 모니터링하고 이러한 변경에 대한 이메일을 보냅니다.
Azure CLI: 리소스 그룹에 대한 이벤트 구독 리소스 그룹에 대한 이벤트를 구독하는 샘플 스크립트입니다. WebHook에 이벤트를 보냅니다.
Azure CLI: 리소스 그룹에 대한 이벤트 구독 및 리소스에 대한 필터링 리소스 그룹에 대한 이벤트를 구독하고 하나의 리소스에 대한 이벤트를 필터링하는 샘플 스크립트입니다.
PowerShell: 리소스 그룹에 대한 이벤트 구독 리소스 그룹에 대한 이벤트를 구독하는 샘플 스크립트입니다. WebHook에 이벤트를 보냅니다.
PowerShell: 리소스 그룹에 대한 이벤트 구독 및 리소스에 대한 필터링 리소스 그룹에 대한 이벤트를 구독하고 하나의 리소스에 대한 이벤트를 필터링하는 샘플 스크립트입니다.
Resource Manager 템플릿: 리소스 구독 Azure 구독 또는 리소스 그룹에 대한 이벤트를 구독합니다. WebHook에 이벤트를 보냅니다.

다음 단계