我在一个我认为很简单的查询上被 Kusto 击败了...... 我正在制作我的第一本工作簿并使用参数。我可以列出并选择一个资源组,但当选择多个资源组时,我无法使用虚拟机填充以下参数(虚拟机)。
ResourceGroup
将逗号分隔的组名称字符串作为属性 resourcegroup
传递就可以了。我不知道如何将该字符串转换为可用的 where 语句。当我手动将多个资源组串在一起时,我的查询工作得很好,所以我认为我对 Kusto 中的 let
和数组的理解感到困惑。如果有更好的方法来做我想做的事情,请告诉我。
//This will work so long as 1 Resource Group is passed from the previous parameter
resources
| where resourceGroup in ('{ResourceGroup:resourcegroup}') and type =~ microsoft.compute/virtualmachines'
| project value = id , label = name
我发现我可以使用
split('{ResourceGroup:resourcegroup}',",")
获得一个正确的数组,但是,我再次无法将该对象与 where 语句结合起来。
非常感谢任何帮助!
通常有一种方法可以做到这一点:
let resourceGroups = dynamic([{ResourceGroup:resourcegroup}]);// turns even an empty string into a valid array
resources
| where (array_length(resourceGroups)==0 // allows 0 length array to be "all"
or resourceGroup in (resourceGroups)) // or filters to only those in the set
and type =~ microsoft.compute/virtualmachines'
| project value = id , label = name
但是,我认为 Azure Resource Graph 不允许使用这种方式
let
?
如果您收到不允许使用
let
的错误,则必须内联执行该动态操作几次:
resources
| where (array_length(dynamic([{ResourceGroup:resourcegroup}]))==0 // allows 0 length array to be "all"
or resourceGroup in (dynamic([{ResourceGroup:resourcegroup}]))) // or filters to only those in the set
and type =~ microsoft.compute/virtualmachines'
| project value = id , label = name
我相信这是实现这一目标的最简单方法 - 按资源组参数过滤:
| where iff(resourceGroup =~ '{ResourceGroup:resourcegroup}', true, false)
这似乎是类型的一些问题,并且如果没有 iif 函数,它似乎不会将结果视为 bool。