Delen via


Informatie over de querytaal van Azure Resource Graph

De querytaal voor Azure Resource Graph ondersteunt veel operators en functies. Elk werk en werkt op basis van Kusto-querytaal (KQL). Voor meer informatie over de querytaal die door Resource Graph wordt gebruikt, begint u met de zelfstudie voor KQL.

In dit artikel worden de taalonderdelen behandeld die worden ondersteund door Resource Graph:

Resource Graph-tabellen

Resource Graph biedt verschillende tabellen voor de gegevens die worden opgeslagen over Azure Resource Manager-resourcetypen en de bijbehorende eigenschappen. Resource Graph-tabellen kunnen worden gebruikt met de join operator om eigenschappen op te halen uit gerelateerde resourcetypen.

Resource Graph-tabellen ondersteunen de join smaken:

Resource Graph-tabel Kunnen join andere tabellen? 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 Bevat resources met betrekking tot Microsoft.Compute virtuele-machineschaalsets.
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 Omvat beheergroep (), abonnement (Microsoft.Management/managementGroupsMicrosoft.Resources/subscriptions) en resourcegroep (Microsoft.Resources/subscriptions/resourcegroups) resourcetypen en gegevens.
Resources Yes De standaardtabel als een tabel niet is gedefinieerd in de query. De meeste Resource Manager-resourcetypen en -eigenschappen zijn hier.
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.

Voor een lijst met tabellen met resourcetypen gaat u naar azure Resource Graph-tabel en resourcetypereferentie.

Note

Resources is de standaardtabel. Tijdens het uitvoeren van query's op de Resources tabel is het niet vereist om de tabelnaam op te geven, tenzij join of union worden gebruikt. Maar de aanbevolen procedure is altijd de eerste tabel in de query op te nemen.

Als u wilt ontdekken welke resourcetypen beschikbaar zijn in elke tabel, gebruikt u Resource Graph Explorer in de portal. Als alternatief kunt u een query gebruiken om <tableName> | distinct type een lijst met resourcetypen op te halen die door de opgegeven Resource Graph-tabel worden ondersteund die in uw omgeving aanwezig zijn.

De volgende query toont een eenvoudige 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

De volgende query toont een complexer gebruik van join. Eerst gebruikt project de query om de velden op te halen van Resources het resourcetype Azure Key Vault-kluizen. 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. Het queryresultaat is één sleutelkluis met het type, de naam, de locatie en de resourcegroep van de sleutelkluis, samen met de naam van het abonnement waarin deze zich bevindt.

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

Voorbeeld: Het aantal virtuele machines ophalen op instanceView.powerState.code:

Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by tostring(properties.extended.instanceView.powerState.code)

Aangepaste taalelementen van Resource Graph

Syntaxis voor gedeelde query's (preview)

As a preview feature, a shared query can be accessed directly in a Resource Graph query. In dit scenario kunt u standaardquery's maken als gedeelde query's en deze opnieuw gebruiken. Als u een gedeelde query wilt aanroepen binnen een Resource Graph-query, gebruikt u de {{shared-query-uri}} syntaxis. The URI of the shared query is the Resource ID of the shared query on the Settings page for that query. In dit voorbeeld is /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OSonze gedeelde query-URI. Deze URI verwijst naar het abonnement, de resourcegroep en de volledige naam van de gedeelde query waarnaar we in een andere query willen verwijzen. Deze query is hetzelfde als de query die is gemaakt in de zelfstudie: Een query maken en delen.

Note

U kunt een query die verwijst naar een gedeelde query niet opslaan als een gedeelde query.

Voorbeeld 1: Alleen de gedeelde query gebruiken:

De resultaten van deze Resource Graph-query zijn hetzelfde als de query die is opgeslagen in de gedeelde query.

{{/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OS}}

Voorbeeld 2: De gedeelde query opnemen als onderdeel van een grotere query:

Deze query maakt eerst gebruik van de gedeelde query en gebruikt limit vervolgens om de resultaten verder te beperken.

{{/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SharedQueries/providers/Microsoft.ResourceGraph/queries/Count VMs by OS}}
| where properties_storageProfile_osDisk_osType =~ 'Windows'

Ondersteunde KQL-taalelementen

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.

Ondersteunde operators op tabellair/hoogste niveau

Hier volgt de lijst met KQL-tabelloperators die worden ondersteund door Resource Graph met specifieke voorbeelden:

KQL Voorbeeldquery resourcegrafiek Notes
count Sleutelkluizen tellen
distinct Resources weergeven die opslag bevatten
extend Virtuele machines tellen op type besturingssysteem
join Sleutelkluis met abonnementsnaam Join flavors supported: innerunique, inner, leftouter, and fullouter. Limiet van drie join of union bewerkingen (of een combinatie van de twee) in één query, geteld samen, waarvan één een join tussen tabellen kan zijn. If all cross-table join use is between Resource and ResourceContainers, then three cross-table join are allowed. Aangepaste joinstrategieën, zoals broadcast join, zijn niet toegestaan. Ga naar join kunnen worden gebruikt.
limit Een lijst van alle openbare IP-adressen weergeven Synoniem van take. Doesn't work with Skip.
mvexpand Gebruik in plaats daarvan een verouderde operator mv-expand . RowLimit max of 2,000. De standaardwaarde is 128.
mv-expand Azure Cosmos DB weergeven met specifieke schrijflocaties RowLimit max of 2,000. De standaardwaarde is 128. Limiet van 3 mv-expand in één query.
order Een lijst van resources weergeven, gesorteerd op naam Synoniem van sort
parse Virtuele netwerken en subnetten van netwerkinterfaces ophalen Het is optimaal om rechtstreeks toegang te krijgen tot eigenschappen als ze bestaan in plaats van te gebruiken parse.
project Een lijst van resources weergeven, gesorteerd op naam
project-away Kolommen verwijderen uit resultaten
sort Een lijst van resources weergeven, gesorteerd op naam Synoniem van order
summarize Azure-resources tellen Alleen vereenvoudigde eerste pagina
take Een lijst van alle openbare IP-adressen weergeven Synoniem van limit. Doesn't work with Skip.
top De eerste vijf virtuele machines weergeven op naam en met hun type besturingssysteem
union Resultaten van twee query's combineren tot één resultaat Eén tabel toegestaan: | union [kind= inner|outer] [withsource=ColumnName] Table. Limiet van drie union benen in één query. Fuzzy resolutie van union beentabellen is niet toegestaan. Might be used within a single table or between the Resources and ResourceContainers tables.
where Resources weergeven die opslag bevatten

Er is een standaardlimiet van drie join en drie mv-expand operators in één Resource Graph SDK-query. U kunt een verhoging van deze limieten voor uw tenant aanvragen via Help en ondersteuning.

To support the Open Query portal experience, Azure Resource Graph Explorer has a higher global limit than Resource Graph SDK.

Note

U kunt niet meerdere keren verwijzen naar een tabel als rechtertabel, die de limiet van 1 overschrijdt. Als u dit doet, ontvangt u een fout met code 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.

De lijst met abonnementen of beheergroepen waarop een query moet worden uitgevoerd, kan handmatig worden gedefinieerd om het bereik van de resultaten te wijzigen. De rest API-eigenschap managementGroups neemt bijvoorbeeld de id van de beheergroep op, die verschilt van de naam van de beheergroep. Wanneer managementGroups dit is opgegeven, worden resources uit de eerste 10.000 abonnementen in of onder de opgegeven beheergroephiërarchie opgenomen. managementGroups kan niet tegelijkertijd worden gebruikt als subscriptions.

Voorbeeld: Voer een query uit op alle resources binnen de hiërarchie van de beheergroep met de naam My Management Group id 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 Met de parameter kunt u Azure Policy-toewijzingen en azure RBAC-roltoewijzingen (op rollen gebaseerd toegangsbeheer) weergeven in de AuthorizationResources tabel die worden overgenomen van hogere bereiken. De AuthorizationScopeFilter parameter accepteert de volgende waarden voor de PolicyResources en AuthorizationResources tabellen:

  • 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
    
  • Voorbeeld van aanvraagtekst

    {
      "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
    
  • Voorbeeld van aanvraagtekst

    {
      "options": {
        "authorizationScopeFilter": "AtScopeAndAbove"
      },
      "query": "PolicyResources | where type =~ 'Microsoft.Authorization/PolicyAssignments'",
      "subscriptions": ["mySubscriptionId"]
    }
    

Escape characters

Sommige eigenschapsnamen, zoals namen met een . of $, moeten worden verpakt of escaped in de query of de naam van de eigenschap wordt onjuist geïnterpreteerd en levert de verwachte resultaten niet op.

  • Punt (.): Plaats de naam ['propertyname.withaperiod'] van de eigenschap tussen vierkante haken.

    Example query that wraps the property odata.type:

    where type=~'Microsoft.Insights/alertRules' | project name, properties.condition.['odata.type']
    
  • Dollarteken ($): Escape het teken in de naam van de eigenschap. Het gebruikte escape-teken is afhankelijk van de shell waarop Resource Graph wordt uitgevoerd.

    • 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