资源和资源组的 Azure 工作簿参数

发布于 2025-01-09 12:55:00 字数 671 浏览 1 评论 0原文

我被 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 语句。

非常感谢任何帮助!

I've been defeated by Kusto on what I thought to be a simple query...
I'm making my first workbook and playing with parameters. I can list and select a Resource Group, but I can't make the following parameter (Virtual Machines) populate with the VMs when more than one Resource Group is selected. The ResourceGroup passes a comma delineated string of the group names as a property resourcegroup just fine. I cannot figure out how to translate that string into a usable where-statement. My query works just fine when I manually string several Resource Groups together so I assume I'm getting burned by my understanding of let and arrays in Kusto. If there is a better way of doing what I'm trying to do, please let me know.

//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

I've figured out I can get a proper array with split('{ResourceGroup:resourcegroup}',","), but, again, I haven't been able to marry up that object with a where-statement.

Any help is much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赏烟花じ飞满天 2025-01-16 12:55:00

https:// /github.com/microsoft/Application-Insights-Workbooks/blob/master/Documentation/Parameters/DropDown.md#special-casing-all

通常有一种方法可以做到这一点:

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

in https://github.com/microsoft/Application-Insights-Workbooks/blob/master/Documentation/Parameters/DropDown.md#special-casing-all

NORMALLY there is a way to do this:

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

however, i don't think Azure Resource Graph allows using let this way?

if you get an error that let isn't allowed, you'll have to do that dynamic thing inline a couple times instead:

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
一场信仰旅途 2025-01-16 12:55:00

我相信这是实现这一目标的最简单方法 - 通过资源组参数进行过滤:

|其中 iff(resourceGroup =~ '{ResourceGroup:resourcegroup}', true, false)

这似乎是类型的一些问题,并且如果没有 iif 函数,它似乎不会将结果视为 bool。

I believe this is the easiest way to achieve just that - filtering by the resource group param:

| where iff(resourceGroup =~ '{ResourceGroup:resourcegroup}', true, false)

It seems to be some issue with the types, and without the iif function it doesn't seem to consider the result as bool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文