Azure Nibble – Hosts File Generator using KQL for App Services

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 kno…



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:

rge

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:

scope

Then select Run query:

run

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.

save

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

.ltag__user__id__620034 .follow-action-button {
background-color: #0cbb58 !important;
color: #000000 !important;
border-color: #0cbb58 !important;
}

pwd9000 image


Print Share Comment Cite Upload Translate
APA
Marcel.L | Sciencx (2024-03-28T19:19:29+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/.
MLA
" » Azure Nibble – Hosts File Generator using KQL for App Services." Marcel.L | Sciencx - Wednesday September 8, 2021, https://www.scien.cx/2021/09/08/azure-nibble-hosts-file-generator-using-kql-for-app-services/
HARVARD
Marcel.L | Sciencx Wednesday September 8, 2021 » Azure Nibble – Hosts File Generator using KQL for App Services., viewed 2024-03-28T19:19:29+00:00,<https://www.scien.cx/2021/09/08/azure-nibble-hosts-file-generator-using-kql-for-app-services/>
VANCOUVER
Marcel.L | Sciencx - » Azure Nibble – Hosts File Generator using KQL for App Services. [Internet]. [Accessed 2024-03-28T19:19:29+00:00]. Available from: https://www.scien.cx/2021/09/08/azure-nibble-hosts-file-generator-using-kql-for-app-services/
CHICAGO
" » Azure Nibble – Hosts File Generator using KQL for App Services." Marcel.L | Sciencx - Accessed 2024-03-28T19:19:29+00:00. https://www.scien.cx/2021/09/08/azure-nibble-hosts-file-generator-using-kql-for-app-services/
IEEE
" » Azure Nibble – Hosts File Generator using KQL for App Services." Marcel.L | Sciencx [Online]. Available: https://www.scien.cx/2021/09/08/azure-nibble-hosts-file-generator-using-kql-for-app-services/. [Accessed: 2024-03-28T19:19:29+00:00]
rf:citation
» Azure Nibble – Hosts File Generator using KQL for App Services | Marcel.L | Sciencx | https://www.scien.cx/2021/09/08/azure-nibble-hosts-file-generator-using-kql-for-app-services/ | 2024-03-28T19:19:29+00:00
https://github.com/addpipe/simple-recorderjs-demo