如何使用 Azure 资源图形资源管理器查询检索给定子网下的所有资源

问题描述 投票:0回答:1

我正在使用 Azure Web App 服务,该服务已配置虚拟网络与出站子网的集成: enter image description here

我想列出与给定子网关联的所有资源:“snet-dev”。 我创建了一个查询并在 Azure Resource Graph Explorer 中运行: enter image description here

查询是:

Resources
| where type =~ "microsoft.network/networkinterfaces"
| extend subnetId = tostring(properties.ipConfigurations[0].properties.subnet.id)
| where subnetId contains "snet-dev"  
| project id, name, resourceGroup, location, subnetId

不幸的是,没有获取任何结果。 我尝试在没有“where”的情况下运行查询,但随后我得到了很多结果来手动查找给定子网的资源。

如何编写一个查询,将所有链接的资源返回给给定的子网?

azure kql azure-virtual-network subnet azure-resource-graph
1个回答
0
投票

我有几个 Azure Web App 服务配置了虚拟网络集成,其出站子网名为 “snet-dev”,如下所示:

enter image description here

最初,当我在我的环境中运行与您相同的查询时,我也得到了空结果,如下所示:

Resources
| where type =~ "microsoft.network/networkinterfaces"
| extend subnetId = tostring(properties.ipConfigurations[0].properties.subnet.id)
| where subnetId contains "snet-dev"  
| project id, name, resourceGroup, location, subnetId

回复:

enter image description here

要使用 Azure Resource Graph Explorer 检索名为 “snet-dev” 的子网下的所有 Azure Web App 资源,您可以运行以下查询:

resources
| where type =~ "microsoft.web/sites" // Search for Azure Web Apps
| extend subnetID = tostring(properties.virtualNetworkSubnetId)
| where isnotempty(subnetID) 
| extend extractedSubnetName = tostring(split(subnetID, '/')[10]) // Extract subnet name from the full virtualNetworkSubnetId path
| where extractedSubnetName == "snet-dev" 
| project webAppId = id, webAppName = name, subnetID, extractedSubnetName

回复:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.