List all UDR User Defined Routes in one query using Azure Resource Graph


azure

The kusto query below will give you a list of all manually added routes/UDRs in all of your Route Tables(RT) in all subnets in all subscriptions. (Where you have access).
This is a great way to keep track of your UDRs…lest they get out of hand…

You will get the following info from each UDR:

Subcription Name
Resource Group Name
Subnet Name
RT Name
UDR Name
Target Prefix
Next Hop Type
Next Hop IP Address
Provisioning State
Has BGP Override

In my current Azure network, the total UDR count is around 413, in 39 different RTs. Its not easy to keep track and t-shoot the network, not easy at all.

Use different sort or where clauses to filter and sort on what you are currently looking for, if you for example filter on
| where addressPrefix == ‘0.0.0.0/0’
you will see only the routes for ‘unrouted’ traffic.
| where nextHopType == ‘VirtualAppliance’
will list all routes to your(?) Virtual appliance Firewall, and so on.
(You can add the where clauses at the end below the last line)

resources
| where type =~ "Microsoft.Network/routeTables"
| mv-expand rules = properties.routes
| join kind=leftouter (resourcecontainers 
| where type=='microsoft.resources/subscriptions' 
| project SubcriptionName=name, subscriptionId) on subscriptionId
| extend subnet_name = split((split(tostring(properties.subnets), '/'))[10], '"')[0]
| extend addressPrefix = tostring(rules.properties.addressPrefix)
| extend nextHopType = tostring(rules.properties.nextHopType)
| extend nextHopIpAddress = tostring(rules.properties.nextHopIpAddress)
| extend hasBgpOverride = tostring(rules.properties.hasBgpOverride)
| extend provisioningState = tostring(rules.properties.provisioningState)
| extend udrname = rules.name
| extend rtname = name
| project SubcriptionName, resourceGroup, subnet_name, rtname, udrname, addressPrefix, nextHopType, nextHopIpAddress, provisioningState, hasBgpOverride
| sort by SubcriptionName, resourceGroup asc, rtname asc, addressPrefix asc
The result looks something like this:
UDRKusto
Happy resource mining!

References
https://docs.microsoft.com/en-us/azure/governance/resource-graph/samples/advanced?tabs=azure-cli


___________________________________________________________________________________________________

Enjoy!

Regards

 Thomas Odell Balkeståhl on LinkedIn

Advertisement

4 thoughts on “List all UDR User Defined Routes in one query using Azure Resource Graph

  1. it might be me, as I am a bit of a noob at Kusto and Graph, but I cannot get this to work! can you show the actual command you run?

    1. Hi, sorry for the really slow response here…
      For anyone interested, its the query in the post, paste it as is and run
      resources
      | where type =~ “Microsoft.Network/routeTables”
      | mv-expand rules = properties.routes
      | join kind=leftouter (resourcecontainers
      | where type==’microsoft.resources/subscriptions’
      | project SubcriptionName=name, subscriptionId) on subscriptionId
      | extend subnet_name = split((split(tostring(properties.subnets), ‘/’))[10], ‘”‘)[0]
      | extend addressPrefix = tostring(rules.properties.addressPrefix)
      | extend nextHopType = tostring(rules.properties.nextHopType)
      | extend nextHopIpAddress = tostring(rules.properties.nextHopIpAddress)
      | extend hasBgpOverride = tostring(rules.properties.hasBgpOverride)
      | extend provisioningState = tostring(rules.properties.provisioningState)
      | extend udrname = rules.name
      | extend rtname = name
      | project SubcriptionName, resourceGroup, subnet_name, rtname, udrname, addressPrefix, nextHopType, nextHopIpAddress, provisioningState, hasBgpOverride
      | sort by SubcriptionName, resourceGroup asc, rtname asc, addressPrefix asc

Leave a Reply to Thomas Balkeståhl Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s