0 0
WP Ad Inserter plugin
Read Time:1 Minute, 57 Second

Azure Resource Graph Explorer is a great tool for querying your Azure resources. Through queries, you can quickly produce tables and charts that can then either be downloaded or displayed on an Azure Dashboard. The queries are written in Kusto Query Language (KQL) and many example queries can be found on the Microsoft Docs website. One of the less intuitive scenarios however arises when working with tags.

Tag Queries

When you create a query that returns tags the data comes back as a block of JSON inside a single column. This means you cannot filter, or aggregate data based on a individual tags.

Using mvexpand

The first step in solving this issue is the mvexpand operator. This operator is the opposite of the summarize operator and will break out each tag into separate rows.

1ResourceContainers

2| where type =~ 'microsoft.resources/subscriptions/resourcegroups'

3| mvexpand tags

4| project name, tags

Screenshot of quick query with Azure Grpah Explorer

At this point however, the data is still in JSON and you cannot apply any further checks on it or use it in graphs.

Using extend

The next step is to use the extend operator. This operator is used to add calculated columns to your result set. In our case using this will allow us to read the JSON data from the expand and format it so it becomes plain text.

1ResourceContainers

2| where type =~ 'microsoft.resources/subscriptions/resourcegroups'

3| mvexpand tags

4| extend tagKey = tostring(bag_keys(tags)[0])

5| extend tagValue = tostring(tags[tagKey])

6| project name, tags, tagKey, tagValue

Screenshot of mvexpand being used

Tag Filters

Now the tag data is in plain text columns we can filter to discard values and then apply a group on the values. The resulting data can be shown as a chart can be pinned to an Azure dashboard.

1ResourceContainers

2| where type =~ 'microsoft.resources/subscriptions/resourcegroups'

3| mvexpand tags

4| extend tagKey = tostring(bag_keys(tags)[0])

5| extend tagValue = tostring(tags[tagKey])

6| where tagKey =~ "Team"

7| summarize count() by tagValue

Screenshot of Azure Grpah Explorer chart using tags

Summary

Azure Resource Graph Explorer is a powerful tool however in some queries it will return JSON data inside a single column. In this post we looked at how can use the mvexpand and extend operators to take JSON columns and extract both the key and values. From this we are then able to filter and aggregate the data to create charts.

Source: https://www.blueboxes.co.uk/working-with-tags-in-azure-resource-graph-explorer

Previous post Stack in C++
How to install Java SE Development Kit on Windows Next post How to install Java SE Development Kit on Windows

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.