Azure Resource Graph의 쿼리 언어는 다양한 연산자와 함수를 지원합니다. 각각은 KQL(Kusto Query Language)을 기반으로 작동합니다. Resource Graph에서 사용하는 쿼리 언어에 대해 알아보려면 KQL에 대한 자습서로 시작하세요.
이 문서에서는 Resource Graph에서 지원하는 언어 구성 요소에 대해 설명합니다.
Resource Graph 테이블
Resource Graph는 Azure Resource Manager 리소스 종류 및 해당 속성에 관해 저장하는 데이터에 대한 여러 테이블을 제공합니다. Resource Graph 테이블은 join
연산자와 함께 사용하여 관련 리소스 종류에서 속성을 가져올 수 있습니다.
Resource Graph 테이블은 join
버전을 지원합니다.
Resource Graph 테이블 | 다른 테이블을 join 할 수 있나요? |
Description |
---|---|---|
AdvisorResources | Yes | Includes resources related to Microsoft.Advisor . |
AlertsManagementResources | Yes | Includes resources related to Microsoft.AlertsManagement . |
AppServiceResources | Yes | Includes resources related to Microsoft.Web . |
AuthorizationResources | Yes | Includes resources related to Microsoft.Authorization . |
AWSResources | Yes | Includes resources related to Microsoft.AwsConnector . |
AzureBusinessContinuityResources | Yes | Includes resources related to Microsoft.AzureBusinessContinuity . |
ChaosResources | Yes | Includes resources related to Microsoft.Chaos . |
CommunityGalleryResources | Yes | Includes resources related to Microsoft.Compute . |
ComputeResources | Yes |
Microsoft.Compute Virtual Machine Scale Sets와 관련된 리소스를 포함합니다. |
DesktopVirtualizationResources | Yes | Includes resources related to Microsoft.DesktopVirtualization . |
DnsResources | Yes | Includes resources related to Microsoft.Network . |
EdgeOrderResources | Yes | Includes resources related to Microsoft.EdgeOrder . |
ElasticsanResources | Yes | Includes resources related to Microsoft.ElasticSan . |
ExtendedLocationResources | Yes | Includes resources related to Microsoft.ExtendedLocation . |
FeatureResources | Yes | Includes resources related to Microsoft.Features . |
GuestConfigurationResources | Yes | Includes resources related to Microsoft.GuestConfiguration . |
HealthResourceChanges | Yes | Includes resources related to Microsoft.Resources . |
HealthResources | Yes | Includes resources related to Microsoft.ResourceHealth . |
InsightsResources | Yes | Includes resources related to Microsoft.Insights . |
IoTSecurityResources | Yes | Includes resources related to Microsoft.IoTSecurity and Microsoft.IoTFirmwareDefense . |
KubernetesConfigurationResources | Yes | Includes resources related to Microsoft.KubernetesConfiguration . |
KustoResources | Yes | Includes resources related to Microsoft.Kusto . |
MaintenanceResources | Yes | Includes resources related to Microsoft.Maintenance . |
ManagedServicesResources | Yes | Includes resources related to Microsoft.ManagedServices . |
MigrateResources | Yes | Includes resources related to Microsoft.OffAzure . |
NetworkResources | Yes | Includes resources related to Microsoft.Network . |
PatchAssessmentResources | Yes | Includes resources related to Azure Virtual Machines patch assessment Microsoft.Compute and Microsoft.HybridCompute . |
PatchInstallationResources | Yes | Includes resources related to Azure Virtual Machines patch installation Microsoft.Compute and Microsoft.HybridCompute . |
PolicyResources | Yes | Includes resources related to Microsoft.PolicyInsights . |
RecoveryServicesResources | Yes | Includes resources related to Microsoft.DataProtection and Microsoft.RecoveryServices . |
ResourceChanges | Yes | Includes resources related to Microsoft.Resources . |
ResourceContainerChanges | Yes | Includes resources related to Microsoft.Resources . |
ResourceContainers | Yes | 관리 그룹(Microsoft.Management/managementGroups ), 구독(Microsoft.Resources/subscriptions ) 및 리소스 그룹(Microsoft.Resources/subscriptions/resourcegroups ) 리소스 종류 및 데이터를 포함합니다. |
Resources | Yes | 쿼리에 테이블이 정의되지 않은 경우 기본 테이블입니다. 대부분의 Resource Manager 리소스 종류 및 속성이 포함되어 있습니다. |
SecurityResources | Yes | Includes resources related to Microsoft.Security . |
ServiceFabricResources | Yes | Includes resources related to Microsoft.ServiceFabric . |
ServiceHealthResources | Yes | Includes resources related to Microsoft.ResourceHealth/events . |
SpotResources | Yes | Includes resources related to Microsoft.Compute . |
SupportResources | Yes | Includes resources related to Microsoft.Support . |
TagsResources | Yes | Includes resources related to Microsoft.Resources/tagnamespaces . |
리소스 종류가 포함된 테이블 목록을 보려면 Azure Resource Graph 테이블 및 리소스 종류 참조로 이동합니다.
Note
Resources
는 기본 테이블입니다.
Resources
테이블을 쿼리하는 동안 join
또는 union
을 사용하지 않는 한 테이블 이름을 제공할 필요가 없습니다. 그러나 권장되는 방법은 항상 쿼리에 초기 테이블을 포함하는 것입니다.
각 테이블에서 사용할 수 있는 리소스 종류를 검색하려면 포털의 Resource Graph 탐색기를 사용합니다. 또는 <tableName> | distinct type
쿼리를 사용하여 해당 환경에 존재하는, 지정된 Resource Graph 테이블이 지원하는 리소스 종류의 목록을 가져올 수 있습니다.
다음 쿼리는 단순한 join
을 보여 줍니다. The query result blends the columns together and any duplicate column names from the joined table, ResourceContainers in this example, are appended with 1. As ResourceContainers table has types for both subscriptions and resource groups, either type might be used to join to the resource from Resources
table.
Resources
| join ResourceContainers on subscriptionId
| limit 1
다음 쿼리는 join
의 더 복잡한 사용법을 보여 줍니다. 먼저 쿼리는 project
를 사용하여 Azure Key Vault 자격 증명 모음 리소스 종류에 대해 Resources
에서 필드를 가져옵니다. The next step uses join
to merge the results with ResourceContainers where the type is a subscription on a property that is both in the first table's project
and the joined table's project
. The field rename avoids join
adding it as name1 since the property already is projected from Resources
. 쿼리 결과는 키 자격 증명 모음의 유형, 이름, 위치 및 리소스 그룹과 해당 모음이 있는 구독 이름을 표시하는 단일 키 자격 증명 모음입니다.
Resources
| where type == 'microsoft.keyvault/vaults'
| project name, type, ___location, subscriptionId, resourceGroup
| join (ResourceContainers | where type=='microsoft.resources/subscriptions' | project SubName=name, subscriptionId) on subscriptionId
| project type, name, ___location, resourceGroup, SubName
| limit 1
Note
When limiting the join
results with project
, the property used by join
to relate the two tables, subscriptionId in the above example, must be included in project
.
Extended properties
As a preview feature, some of the resource types in Resource Graph have more type-related properties available to query beyond the properties provided by Azure Resource Manager. This set of values, known as extended properties, exists on a supported resource type in properties.extended
. To show resource types with extended properties, use the following query:
Resources
| where isnotnull(properties.extended)
| distinct type
| order by type asc
예: instanceView.powerState.code
를 기준으로 가상 컴퓨터 수 가져오기:
Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by tostring(properties.extended.instanceView.powerState.code)
Resource Graph 사용자 지정 언어 요소
공유 쿼리 구문(미리 보기)
As a preview feature, a shared query can be accessed directly in a Resource Graph query. 이 시나리오에서는 표준 쿼리를 공유 쿼리로 만들고 다시 사용할 수 있습니다. Resource Graph 쿼리 내에서 공유 쿼리를 호출하려면 {{shared-query-uri}}
구문을 사용합니다. The URI of the shared query is the Resource ID of the shared query on the Settings page for that query. 이 예에서 공유 쿼리 URI는 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OS
입니다.
이 URI는 다른 쿼리에서 참조하려는 구독, 리소스 그룹 및 공유 쿼리의 전체 이름을 가리킵니다. 이 쿼리는 자습서: 쿼리 만들기 및 공유에서 만든 쿼리와 동일합니다.
Note
공유 쿼리를 참조하는 쿼리는 공유 쿼리로 저장할 수 없습니다.
예 1: 공유 쿼리만 사용:
이 Resource Graph 쿼리의 결과는 공유 쿼리에 저장된 쿼리와 동일합니다.
{{/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OS}}
예 2: 공유 쿼리를 더 큰 쿼리의 일부로 포함:
이 쿼리는 먼저 공유 쿼리를 사용한 다음 limit
을 사용하여 결과를 추가로 제한합니다.
{{/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OS}}
| where properties_storageProfile_osDisk_osType =~ 'Windows'
지원되는 KQL 언어 요소
Resource Graph supports a subset of KQL data types, scalar functions, scalar operators, and aggregation functions. Specific tabular operators are supported by Resource Graph, some of which have different behaviors.
지원되는 테이블 형식/최상위 수준 연산자
Resource Graph에서 지원하는 KQL 테이블 형식 연산자와 특정 샘플의 목록은 다음과 같습니다.
KQL | Resource Graph 샘플 쿼리 | Notes |
---|---|---|
count | 키 자격 증명 모음 계수 | |
distinct | 스토리지를 포함하는 리소스 표시 | |
extend | OS 유형별 가상 머신 개수 계산 | |
join | 구독 이름이 있는 키 자격 증명 모음 | Join flavors supported: innerunique, inner, leftouter, and fullouter. 단일 쿼리에서 세 join 개 또는 union 연산(또는 둘의 조합)으로 제한되며, 그 중 하나는 테이블 간 조인일 수 있습니다. If all cross-table join use is between Resource and ResourceContainers, then three cross-table join are allowed. 브로드캐스트 조인과 같은 사용자 지정 조인 전략은 허용되지 않습니다.
join 을 사용할 수 있는 테이블은 Resource Graph 테이블을 참조하세요. |
limit | 모든 공용 IP 주소 나열 |
take 의 동의어입니다. Doesn't work with Skip. |
mvexpand | 레거시 연산자. mv-expand 를 대신 사용합니다.
RowLimit max of 2,000. 기본값은 128입니다. |
|
mv-expand | 특정 쓰기 위치를 사용하여 Azure Cosmos DB 나열 |
RowLimit max of 2,000. 기본값은 128입니다. 단일 쿼리의 mv-expand 은 3개로 제한됩니다. |
order | 리소스를 이름별로 나열 |
sort 의 동의어 |
parse | 네트워크 인터페이스의 가상 네트워크 및 서브넷 가져오기 | 속성이 있는 경우 parse 를 사용하는 대신 속성에 직접 액세스하는 것이 적합합니다. |
project | 리소스를 이름별로 나열 | |
project-away | 결과에서 열 제거 | |
sort | 리소스를 이름별로 나열 |
order 의 동의어 |
summarize | Azure 리소스 개수 계산 | 간소화된 첫 페이지만 |
take | 모든 공용 IP 주소 나열 |
limit 의 동의어입니다. Doesn't work with Skip. |
top | 이름 및 해당 OS 유형별로 처음 5개의 가상 머신 표시 | |
union | 두 쿼리의 결과를 단일 결과로 결합 | 단일 테이블 허용: | union [kind= inner|outer] [withsource=ColumnName] Table 단일 쿼리에서는 3개의 union 레그로 제한됩니다.
union 레그 테이블의 유사 항목 확인은 허용되지 않습니다. Might be used within a single table or between the Resources and ResourceContainers tables. |
where | 스토리지를 포함하는 리소스 표시 |
단일 Resource Graph SDK 쿼리에는 기본적으로 join
연산자 3개와 mv-expand
연산자 3개로 제한됩니다.
도움말 + 지원을 통해 테넌트에 대한 이 제한을 늘리도록 요청할 수 있습니다.
To support the Open Query portal experience, Azure Resource Graph Explorer has a higher global limit than Resource Graph SDK.
Note
한도인 1을 초과하면 테이블을 오른쪽 테이블로 여러 번 참조할 수 없습니다. 그렇게 하면 DisallowedMaxNumberOfRemoteTables 코드와 함께 오류가 발생합니다.
Query scope
The scope of the subscriptions or management groups from which resources are returned by a query defaults to a list of subscriptions based on the context of the authorized user. If a management group or a subscription list isn't defined, the query scope is all resources, and includes Azure Lighthouse delegated resources.
쿼리할 구독 또는 관리 그룹 목록을 수동으로 정의하여 결과의 범위를 변경할 수 있습니다. 예를 들어 REST API managementGroups
속성은 관리 그룹의 이름과 다른 관리 그룹 ID를 사용합니다.
managementGroups
가 지정되면 지정된 관리 그룹 계층 구조 내 또는 아래에 있는 처음 10,000개 구독의 리소스가 포함됩니다.
managementGroups
는 subscriptions
와 동시에 사용할 수 없습니다.
예: ID가 My Management Group
인 myMG
이라는 관리 그룹 계층 구조 내의 모든 리소스를 쿼리합니다.
REST API URI
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01
Request Body
{ "query": "Resources | summarize count()", "managementGroups": ["myMG"] }
AuthorizationScopeFilter
매개 변수를 사용하면 상위 범위에서 상속되는 AuthorizationResources
테이블의 Azure Policy 할당 및 Azure RBAC(Azure 역할 기반 액세스 제어) 역할 할당을 나열할 수 있습니다.
AuthorizationScopeFilter
매개 변수는 PolicyResources
및 AuthorizationResources
테이블에 대해 다음 값을 허용합니다.
- AtScopeAndBelow (default if not specified): Returns assignments for the given scope and all child scopes.
- AtScopeAndAbove: Returns assignments for the given scope and all parent scopes, but not child scopes.
- AtScopeAboveAndBelow: Returns assignments for the given scope, all parent scopes, and all child scopes.
- AtScopeExact: Returns assignments only for the given scope; no parent or child scopes are included.
Note
To use the AuthorizationScopeFilter
parameter, be sure to use the 2021-06-01-preview or later API version in your requests.
Example: Get all policy assignments at the myMG management group and Tenant Root (parent) scopes.
REST API URI
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-06-01-preview
요청 본문 샘플
{ "options": { "authorizationScopeFilter": "AtScopeAndAbove" }, "query": "PolicyResources | where type =~ 'Microsoft.Authorization/PolicyAssignments'", "managementGroups": ["myMG"] }
Example: Get all policy assignments at the mySubscriptionId subscription, management group, and Tenant Root scopes.
REST API URI
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-06-01-preview
요청 본문 샘플
{ "options": { "authorizationScopeFilter": "AtScopeAndAbove" }, "query": "PolicyResources | where type =~ 'Microsoft.Authorization/PolicyAssignments'", "subscriptions": ["mySubscriptionId"] }
Escape characters
.
또는 $
를 포함하는 일부 속성 이름은 쿼리에서 래핑하거나 이스케이프해야 합니다. 그렇지 않으면 속성 이름이 올바르게 해석되고 올바른 결과를 제공하지 않습니다.
점(
.
): 대괄호를 사용하여 속성 이름['propertyname.withaperiod']
를 묶습니다.Example query that wraps the property odata.type:
where type=~'Microsoft.Insights/alertRules' | project name, properties.condition.['odata.type']
달러 기호(
$
): 속성 이름의 문자를 이스케이프합니다. 사용되는 이스케이프 문자는 Resource Graph를 실행하는 셸에 따라 다릅니다.Bash: Use a backslash (
\
) as the escape character.Example query that escapes the property $type in Bash:
where type=~'Microsoft.Insights/alertRules' | project name, properties.condition.\$type
cmd: Don't escape the dollar sign (
$
) character.PowerShell: Use a backtick (
`
) as the escape character.Example query that escapes the property $type in PowerShell:
where type=~'Microsoft.Insights/alertRules' | project name, properties.condition.`$type
Next steps
- Azure Resource Graph query language Starter queries and Advanced queries.
- Azure 리소스 탐색 방법에 대해 자세히 알아봅니다.