使用 Azure Resource Graph 排查错误
使用 Azure Resource Graph 查询 Azure 资源时,可能会遇到错误。 本文描述了可能会发生的各种错误及其解决方法。
大多数错误都是关于使用 Azure Resource Graph 运行查询时出现的问题。 当查询失败时,SDK 会提供有关失败查询的详细信息。 此信息会指出存在的问题,以便可以修复问题并确保后续查询成功进行。
进行大量或频繁资源查询的客户受到了请求数限制。
Azure Resource Graph 基于时段为每个用户分配配额数量。 例如,用户可以在每 5 秒的时段内最多发送 15 个查询,而不会受到限制。 配额值取决于多种因素并可能会发生更改。 有关详细信息,请参阅 Azure Resource Graph 中的限制。
有多种方法可处理请求受限问题:
有权访问 1,000 多个订阅(包括使用 Azure Lighthouse 的跨租户订阅)的客户无法通过对 Azure Resource Graph 的一次调用获取所有订阅的数据。
Azure CLI 和 PowerShell 仅将前 1,000 个订阅转发到 Azure Resource Graph。 Azure Resource Graph 的 REST API 接受要对其执行查询的最大订阅数。
对包含订阅子集的查询的请求进行批处理,让子集保持在 1,000 个订阅的限制以内。 解决方法是在 PowerShell 中使用 Subscription 参数。
# Replace this query with your own
$query = 'Resources | project type'
# Fetch the full array of subscription IDs
$subscriptions = Get-AzSubscription
$subscriptionIds = $subscriptions.Id
# Create a counter, set the batch size, and prepare a variable for the results
$counter = [PSCustomObject] @{ Value = 0 }
$batchSize = 1000
$response = @()
# Group the subscriptions into batches
$subscriptionsBatch = $subscriptionIds | Group -Property { [math]::Floor($counter.Value++ / $batchSize) }
# Run the query for each batch
foreach ($batch in $subscriptionsBatch){ $response += Search-AzGraph -Query $query -Subscription $batch.Group }
# View the completed results of the query on all subscriptions
$response
客户查询 Azure Resource Graph REST API 时,返回 500(内部服务器错误)响应。
Azure Resource Graph REST API 仅支持 application/json
的 Content-Type
。 某些 REST 工具或代理默认为 text/plain
,这不受 REST API 支持。
验证用于查询 Azure Resource Graph 的工具或代理是否为 application/json
配置了 REST API 标头 Content-Type
。
客户使用 Azure Resource Graph 查询显式传递订阅列表时,获得 403(禁止)响应。
如果客户没有对提供的所有订阅的读取权限,则该请求将因缺乏相应安全权限而被拒绝。
在订阅列表中至少包含一个订阅,运行查询的客户对其至少具有读取访问权限。 有关详细信息,请参阅 Azure Resource Graph 中的权限。
如果你的问题未在本文中列出,或无法解决问题,请访问支持站点:
Azure 支持站点并提交请求。