This content originally appeared on DEV Community and was authored by Marcel.L
Azure Resource Graph
Azure Resource Graph allows us to quickly and efficiently query across Azure subscriptions. Analyse cloud inventory using complex queries launched programmatically or from the Azure portal. The query language used is known as Kusto Query Lanuage (KQL).
Hosts File Generator
Recently I was looking into a mechanism to generate a hosts file to add a very large number of Azure App services that have been private endpoint enabled for both the default as well as the scm hosts of each app, so that these apps could be tested without/outside of DNS, by using a hosts file instead. This has led me to write a short KQL query that will do just this. I will share this query with you today.
In the Azure portal search for Resource Graph Explorer:
In the query editor add the following lines of code:
Resources
| where type =~ "microsoft.web/sites"
| mvexpand pe = properties.privateEndpointConnections
| extend peip = tostring(pe.properties.ipAddresses[0])
| mvexpand hosts = properties.hostNameSslStates
| project peip, hosts=tostring(hosts.name)
| order by peip asc
You can also select the scope at which you want to run the query:
Then select Run query:
That is it, you can now export the results to a CSV and copy the results over into a hosts txt file. In addition you can also save the query for future re-use to run it again if any private IP addresses of your App services private endpoints change to get an updated hosts file formatted result.
You can also select whether you want to save the query as a private query or a shared query. The later allows you to save the query as an object in a resource group that others can also access and run.
I hope you have enjoyed this post and have learned something new. You can also find the query code sample for this tutorial on my Github page. ❤️
Author
This content originally appeared on DEV Community and was authored by Marcel.L
Marcel.L | Sciencx (2021-09-08T15:29:44+00:00) Azure Nibble – Hosts File Generator using KQL for App Services. Retrieved from https://www.scien.cx/2021/09/08/azure-nibble-hosts-file-generator-using-kql-for-app-services/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.