My goal is to create an Azure dashboard widget with a list of subscriptions with their according policy states.
+-------------------+-------+-----------+--------+---------------+------------+
| Subscription name | Total | Compliant | Exempt | Non-compliant | Percentage |
+-------------------+-------+-----------+--------+---------------+------------+
| foo-subscription | 300 | 270 | 0 | 30 | 0.9 |
| bar-subscription | 100 | 80 | 0 | 20 | 0.8 |
+-------------------+-------+-----------+--------+---------------+------------+
For that I am using the Azure Resource Graph Query. I am able to list the policy states related to the subscription-IDs. But not related to the subscription names.
This query
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
leads to
+--------------------+-------+-----------+--------+---------------+------------+
| 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 |
+--------------------+-------+-----------+--------+---------------+------------+
The kusto language allows to join tables. However, the kusto language allows the join only for Resources and ResourceContainer tables. Not for Policy resources.
Is it possible to create a table related to the subscription name?