我的目标是创建一个 Azure 仪表板小部件,其中包含订阅列表及其相应的策略状态。
+-------------------+-------+-----------+--------+---------------+------------+
| Subscription name | Total | Compliant | Exempt | Non-compliant | Percentage |
+-------------------+-------+-----------+--------+---------------+------------+
| foo-subscription | 300 | 270 | 0 | 30 | 0.9 |
| bar-subscription | 100 | 80 | 0 | 20 | 0.8 |
+-------------------+-------+-----------+--------+---------------+------------+
为此,我使用 Azure Resource Graph Query。我能够列出与订阅 ID 相关的策略状态。但与订阅名称无关。
这个查询
policyresources
| extend complianceState=tostring(properties['complianceState']), resourceId=tostring(properties['resourceId'])
| project subscriptionId, complianceState, resourceId
| summarize complianceStates=make_list(complianceState) by subscriptionId, resourceId
| summarize Total = count()
, Compliant = countif((complianceStates notcontains "NonCompliant") and (complianceStates contains "Compliant"))
, Exempt = countif((complianceStates notcontains "NonCompliant") and (complianceStates notcontains "Compliant") and (complianceStates contains "Exempt"))
, NonCompliant = countif (complianceStates contains "NonCompliant")
by subscriptionId
| extend OverallCompliancePerc = round(toreal(Compliant + Exempt) / toreal(Total), 2)
| order by OverallCompliancePerc desc
导致
+--------------------+-------+-----------+--------+---------------+------------+
| Subscription-ID | Total | Compliant | Exempt | Non-compliant | Percentage |
+--------------------+-------+-----------+--------+---------------+------------+
| b4757628-9b24-447a | 300 | 270 | 0 | 30 | 0.9 |
| 86fa64ae-6c30-4157 | 100 | 80 | 0 | 20 | 0.8 |
+--------------------+-------+-----------+--------+---------------+------------+
kusto 语言允许加入表。但是,kusto 语言只允许对 Resources 和 ResourceContainer 表进行连接。不适用于政策资源。
是否可以创建与订阅名称相关的表?