简体   繁体   English

KQL:: 只返回超过 4 条记录的标签

[英]KQL :: return only tags with more than 4 records

I have created a Kusto query that allows me to return all our database park.我创建了一个 Kusto 查询,允许我返回我们所有的数据库公园。 The query only takes 10 lines of code:查询只需要10行代码:

Resources
| join kind=inner (
    resourcecontainers
    | where type == 'microsoft.resources/subscriptions'
    | project subscriptionId, subscriptionName = name)
    on subscriptionId
| where subscriptionName in~ ('Subscription1','Subscription2')
| where type =~ 'microsoft.sql/servers/databases'
| where name != 'master'
| project  subscriptionName, resourceGroup, name, type, location,sku.tier, properties.requestedServiceObjectiveName, tags.customerCode

By contract we are supposed to give only 4 Azure SQL Database per customer but sometimes developers take a copy of them and they rename it _old or _backup and suddenly a customer can have 5 or 6 databases.根据合同,我们应该只为每个客户提供 4 个 Azure SQL 数据库,但有时开发人员会复制一份并将其重命名为_old_backup ,突然一个客户可以拥有 5 或 6 个数据库。

This increase the overall costs of the Cloud and I would like to have a list of all customers that have more than 4 databases.这增加了云的总体成本,我想列出拥有 4 个以上数据库的所有客户。

In order to do so I can use the tag tags.customerCode which has the 3 letters identifier for each customer.为此,我可以使用标签tags.customerCode ,它具有每个客户的 3 个字母标识符。

The code should work like this: if a customer is called ABC and there are 4 Azure SQL Databases with tags.customerCode ABC the query should return nothing.代码应该像这样工作:如果一个客户被称为 ABC 并且有 4 个 Azure SQL 带有tags.customerCode ABC 的数据库,查询应该不返回任何内容。 If there are 5 or 6 databases with tags.customerCode ABC the query should return all of them.如果有 5 或 6 个数据库带有tags.customerCode ABC,则查询应返回所有这些数据库。

Not sure if Kusto can be that flexible.不确定 Kusto 是否可以那么灵活。

Here is a possible solution.这是一个可能的解决方案。
It should be noted that Azure resource graph supports only a limited subset of KQL.需要注意的是,Azure 资源图只支持有限的 KQL 子集。

resourcecontainers 
| where     type == 'microsoft.resources/subscriptions'
        //and name in~ ('Subscription1','Subscription2')
| project subscriptionId, subscriptionName = name
| join kind=inner  
  (
    resources
    | where     type =~ 'microsoft.sql/servers/databases'
            and name != 'master'
  )
  on  subscriptionId            
| project   subscriptionId, subscriptionName, resourceGroup, name, type, location
           ,tier                            = sku.tier
           ,requestedServiceObjectiveName   = properties.requestedServiceObjectiveName
           ,customerCode                    = tostring(tags.customerCode)    
| summarize dbs = count(), details = make_list(pack_all()) by customerCode
| where dbs > 4
| mv-expand with_itemindex=db_seq ['details']
| project   customerCode
           ,dbs
           ,db_seq = db_seq + 1
           ,subscriptionId                  = details.subscriptionId
           ,subscriptionName                = details.subscriptionName
           ,resourceGroup                   = details.resourceGroup
           ,name                            = details.name
           ,type                            = details.type
           ,location                        = details.location
           ,tier                            = details.tier
           ,requestedServiceObjectiveName   = details.requestedServiceObjectiveName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建一个新表,只保留Bigquery中相同ID下超过5条数据记录的行 - How to create a new table that only keeps rows with more than 5 data records under the same id in Bigquery KQL 查询仅连接具有列值的表 - KQL query to only join tables with a column value KQL / Azure Resource Graph Explorer:组合来自多个记录的值 - KQL / Azure Resource Graph Explorer: combine values from multiple records 如何返回特定列中只有 integer 个值的所有记录? - How to return all records having only integer values in a specific column? 如何使用查询从 azure cosmos db 使用 cosmos batch 存储超过 100 条记录 - How to store more than 100 records using cosmos batch from azure cosmos db using query KQL - 每小时检查一次值,看它是否高于一周平均值 - KQL - Check value every hour to see if it's higher than the week average 如何使用 kql 查询查找哪个 pod 在 AKS 集群中摄取更多数据? - How to find which pod is taking more data ingestion in AKS cluster using kql query? WSO2 REST API:如何在GET请求中返回多行 - WSO2 REST API: How to return more than one row in the GET request Azure python sdk 存储表备份表返回1000多行 - Azure python sdk storage table backup table Return more than 1000 rows 使用“添加或修改 blob 时(仅限属性)(V2)”时检索多个 blob - Retrieving more than one blob when using "When a blob is added or modified (properties only) (V2)"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM