gpt4 book ai didi

Azure Resource Graph Query to retrieve all resources of applications using resource groups based on application ID(Azure资源图查询,用于使用基于应用程序ID的资源组检索应用程序的所有资源)

转载 作者:bug小助手 更新时间:2023-10-22 15:58:58 26 4
gpt4 key购买 nike



In my azure portal I have 6 separate applications, I have to list all of the employed resources using Azure Resource Graph query, but some of the applications' resources have no app_id tag. Therefore, when I filter the query based on app_id tag, the result of the query does not retrieve all of the resources. For example, if I have total 100 resources in those 6 applications, it brings 80 of them which have app_id tag. In this case, my question is that what would be the best approach to bring all of the resources belonging my applications using Azure Resource Graph query.

在我的azure门户中,我有6个独立的应用程序,我必须使用azure资源图查询列出所有使用的资源,但有些应用程序的资源没有app_id标记。因此,当我基于app_id标记筛选查询时,查询的结果不会检索到所有资源。例如,如果我在这6个应用程序中总共有100个资源,那么它会带来其中80个具有app_id标记的资源。在这种情况下,我的问题是,使用Azure资源图查询来获取属于我的应用程序的所有资源的最佳方法是什么。


Additionally, I thought one possible way to get this output would be joining resource groups of all those applications based on app_id filter since when I filter only the resource group names in the query, it brings the desired output but, the issue is some applications may have multiple resource groups while some only one. At this point, I also would love to receive your feedback regarding how can I write this query/clause/condition to filter respective resource groups based on app_id tag, then take every resource from within this resource groups?

此外,我认为获得此输出的一种可能方法是基于app_id过滤器加入所有这些应用程序的资源组,因为当我只过滤查询中的资源组名称时,它会带来所需的输出,但问题是有些应用程序可能有多个资源组,而有些应用程序只有一个。在这一点上,我也很想收到您的反馈,关于我如何编写这个查询/子句/条件来基于app_id标记过滤各个资源组,然后从这个资源组中获取每个资源?


更多回答
优秀答案推荐

You can union queries as below. Also i highly suggest to add Tags when you create the resources (or after). Tags are useful for tracking resources without any boundries. You can create an application tag and assign it to multiple resources or create appname1 and appname2 tag to assing multiple application to one resource. After you tagged resources you can query them by tag. Without changing resource groups.

您可以按如下方式联合查询。此外,我强烈建议在创建资源时(或之后)添加标签。标签对于在没有任何边界的情况下跟踪资源非常有用。您可以创建一个应用程序标记并将其分配给多个资源,也可以创建appname1和appname2标记以将多个应用程序分配给一个资源。标记资源后,可以通过标记进行查询。不更改资源组。


union
(
// Query 1: Resources with app_id tag
resources
| where type =~ "Microsoft.*" // Optionally, filter resources by type
| where isnotnull(tags['app_id'])
| project ...
),
(
// Query 2: Resources without app_id tag
resources
| where type =~ "Microsoft.*" // Optionally, filter resources by type
| where isnull(tags['app_id'])
| project ...
)

更多回答

Hi, thanks a lot for your valuable feedback. However, all the resource groups have 'app_id' tag even the resources belonging to those groups have no. Therefore, I need to query the results on resource group level, and your answer still gives correct but inconsistent results because 'app_id' attribute should have no null values in the output for merging purposes with different tables from different databases. Is there any way to retrieve the data based on resource group level by filtering still on app_id tag?

嗨,非常感谢您宝贵的反馈。然而,所有的资源组都有“app_id”标记,即使属于这些组的资源也没有。因此,我需要在资源组级别查询结果,您的回答仍然给出了正确但不一致的结果,因为“app_id”属性在输出中不应有空值,以便与来自不同数据库的不同表合并。是否有任何方法可以通过对app_id标签进行过滤来根据资源组级别检索数据?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com