Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Frågespråket för Azure Resource Graph stöder många operatorer och funktioner. Varje arbete och drift baseras på Kusto-frågespråk (KQL). Om du vill veta mer om det frågespråk som används av Resource Graph börjar du med självstudien för KQL.
Den här artikeln beskriver de språkkomponenter som stöds av Resource Graph:
Resource Graph-tabeller
Resource Graph innehåller flera tabeller för de data som lagras om Azure Resource Manager-resurstyper och deras egenskaper. Resource Graph-tabeller kan användas med operatorn join för att hämta egenskaper från relaterade resurstyper.
Resource Graph-tabeller stöder smakerna join :
| Resource Graph-tabell | Kan join andra tabeller? |
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 | Innehåller resurser som är relaterade till Microsoft.Compute VM-skalningsuppsättningar. |
| 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 | Innehåller resurstyper och data för hanteringsgrupp (Microsoft.Management/managementGroups), prenumeration (Microsoft.Resources/subscriptions) och resursgrupp (Microsoft.Resources/subscriptions/resourcegroups). |
| Resources | Yes | Standardtabellen om en tabell inte har definierats i frågan. De flesta Resource Manager-resurstyper och egenskaper finns här. |
| 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. |
En lista över tabeller som innehåller resurstyper finns i tabellen Azure Resource Graph och resurstypsreferensen.
Note
Resources är standardtabellen. När du kör frågor mot Resources tabellen krävs det inte att du anger tabellnamnet såvida inte join eller union används. Men den rekommenderade metoden är att alltid inkludera den inledande tabellen i frågan.
Om du vill ta reda på vilka resurstyper som är tillgängliga i varje tabell använder du Resource Graph Explorer i portalen. Du kan också använda en fråga, till exempel <tableName> | distinct type för att hämta en lista över resurstyper som den angivna Resource Graph-tabellen stöder i din miljö.
Följande fråga visar en enkel 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
Följande fråga visar en mer komplex användning av join. Först använder project frågan för att hämta fälten från Resources för resurstypen Azure Key Vault-valv. 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. Frågeresultatet är en enda nyckelvalv som visar typ, namn, plats och resursgrupp för nyckelvalvet, tillsammans med namnet på den prenumeration som det finns i.
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
Exempel: Hämta antalet virtuella datorer genom instanceView.powerState.codeatt :
Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by tostring(properties.extended.instanceView.powerState.code)
Anpassade språkelement för Resource Graph
Syntax för delad fråga (förhandsversion)
As a preview feature, a shared query can be accessed directly in a Resource Graph query. Det här scenariot gör det möjligt att skapa standardfrågor som delade frågor och återanvända dem. Om du vill anropa en delad fråga i en Resource Graph-fråga använder du syntaxen {{shared-query-uri}} . The URI of the shared query is the Resource ID of the shared query on the Settings page for that query. I det här exemplet är /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OSvår delade fråge-URI .
Den här URI:n pekar på prenumerationen, resursgruppen och det fullständiga namnet på den delade fråga som vi vill referera till i en annan fråga. Den här frågan är densamma som den som skapades i Självstudie: Skapa och dela en fråga.
Note
Du kan inte spara en fråga som refererar till en delad fråga som en delad fråga.
Exempel 1: Använd endast den delade frågan:
Resultatet av den här Resource Graph-frågan är samma som frågan som lagras i den delade frågan.
{{/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OS}}
Exempel 2: Inkludera den delade frågan som en del av en större fråga:
Den här frågan använder först den delade frågan och använder limit sedan för att ytterligare begränsa resultaten.
{{/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OS}}
| where properties_storageProfile_osDisk_osType =~ 'Windows'
KQL-språkelement som stöds
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.
Operatorer på tabell-/toppnivå som stöds
Här är listan över KQL-tabelloperatorer som stöds av Resource Graph med specifika exempel:
| KQL | Resource Graph-exempelfråga | Notes |
|---|---|---|
| count | Räkna nyckelvalv | |
| distinct | Visning av resurser med lagring | |
| extend | Antal virtuella datorer efter OS-typ | |
| join | Nyckelvalv med prenumerationsnamn | Join flavors supported: innerunique, inner, leftouter, and fullouter. Gränsen på tre join eller union åtgärder (eller en kombination av de två) i en enda fråga, räknas tillsammans, varav en kan vara en koppling mellan tabeller. If all cross-table join use is between Resource and ResourceContainers, then three cross-table join are allowed. Anpassade anslutningsstrategier, till exempel sändningskoppling, tillåts inte. För vilka tabeller kan använda joingår du till Resource Graph-tabeller. |
| limit | Lista över alla offentliga IP-adresser |
takeSynonymen för . Doesn't work with Skip. |
| mvexpand | Äldre operator, använd mv-expand i stället.
RowLimit max of 2,000. Standardvärdet är 128. |
|
| mv-expand | Lista Azure Cosmos DB med specifika skrivplatser |
RowLimit max of 2,000. Standardvärdet är 128. Gräns på 3 mv-expand i en enskild fråga. |
| order | Lista över resurser sorterade efter namn | Synonym till sort |
| parse | Hämta virtuella nätverk och undernät för nätverksgränssnitt | Det är optimalt att komma åt egenskaper direkt om de finns i stället för att använda parse. |
| project | Lista över resurser sorterade efter namn | |
| project-away | Ta bort kolumner från resultat | |
| sort | Lista över resurser sorterade efter namn | Synonym till order |
| summarize | Antal Azure-resurser | Endast förenklad förstasida |
| take | Lista över alla offentliga IP-adresser |
limitSynonymen för . Doesn't work with Skip. |
| top | Visning av de första fem virtuella datorerna efter namn och OS-typ | |
| union | Kombinera resultat från två frågor till ett enda resultat | Enkel tabell tillåts: | union [kind= inner|outer] [withsource=ColumnName] Table. Gräns på tre union ben i en enda fråga. Fuzzy-upplösning för union bentabeller tillåts inte. Might be used within a single table or between the Resources and ResourceContainers tables. |
| where | Visning av resurser med lagring |
Det finns en standardgräns på tre join och tre mv-expand operatorer i en enda Resource Graph SDK-fråga. Du kan begära en ökning av dessa gränser för din klientorganisation via Hjälp + support.
To support the Open Query portal experience, Azure Resource Graph Explorer has a higher global limit than Resource Graph SDK.
Note
Du kan inte referera till en tabell som rätt tabell flera gånger, vilket överskrider gränsen på 1. Om du gör det får du ett fel med koden 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.
Listan över prenumerationer eller hanteringsgrupper som ska frågas kan definieras manuellt för att ändra resultatets omfattning. Egenskapen REST API managementGroups tar till exempel hanteringsgruppens ID, som skiljer sig från namnet på hanteringsgruppen. När managementGroups anges inkluderas resurser från de första 10 000 prenumerationerna i eller under den angivna hanteringsgruppshierarkin.
managementGroups kan inte användas samtidigt som subscriptions.
Exempel: Fråga alla resurser i hierarkin för hanteringsgruppen med namnet My Management Group med ID myMG.
REST API-URI
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01Request Body
{ "query": "Resources | summarize count()", "managementGroups": ["myMG"] }
Med AuthorizationScopeFilter parametern kan du visa en lista över Azure Policy-tilldelningar och rolltilldelningar för Rollbaserad åtkomstkontroll i Azure (Azure RBAC) i tabellen AuthorizationResources som ärvs från de övre omfången. Parametern AuthorizationScopeFilter accepterar följande värden för tabellerna PolicyResources och 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-previewExempel på begärandetext
{ "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-previewExempel på begärandetext
{ "options": { "authorizationScopeFilter": "AtScopeAndAbove" }, "query": "PolicyResources | where type =~ 'Microsoft.Authorization/PolicyAssignments'", "subscriptions": ["mySubscriptionId"] }
Escape characters
Vissa egenskapsnamn, till exempel de som innehåller en . eller $, måste vara omslutna eller undantagna i frågan eller så tolkas egenskapsnamnet felaktigt och ger inte de förväntade resultaten.
Punkt (
.): Omslut egenskapsnamnet['propertyname.withaperiod']med hakparenteser.Example query that wraps the property odata.type:
where type=~'Microsoft.Insights/alertRules' | project name, properties.condition.['odata.type']Dollartecken (
$): Undvik tecknet i egenskapsnamnet. Vilket escape-tecken som används beror på gränssnittet som kör 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.\$typecmd: 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.
- Läs mer om hur du utforskar Azure-resurser.