Azure Resource Graph
Azure Resource Graph is an Azure service designed to extend Azure Resource Management by providing efficient and performant resource exploration with the ability to query at scale across a given set of subscriptions so that you can effectively govern your environment.
These queries provide the following abilities:
Below are few resource types supported by Azure Resource Graph:
How to Explore Azure Graph Explorer on Azure portal:
Go to Azure Portal > Search for Resource Graph
Use Resource Graph Explorer for executing the queries.
Access Resource explorer directly from Resource Group
To list all sites across all subscriptions and resources groups:
resources
| where type == "microsoft.web/sites"
To view all your sites that are located in West US:
resources
| where type == "microsoft.web/sites"
| where location == "westus"
List all your apps by specific property
To view all your running sites, you can drill into the “properties” object: List all your apps by specific property
resources
| where type == "microsoft.web/sites"
| where properties.state == "Running"
List Apps based on Stack
You can drill into properties object for getting stack used by the app, below is the sample query for Python 3.6
resources
| where type == 'microsoft.web/sites'
| where subscriptionId =~ '<SubIdHere>'
| where properties.siteProperties.properties contains "Python|3.6"
To get sites count by region:
resources
| where type == "microsoft.web/sites"
| summarize count() by location
Quickly Discover any expiring certificates for Azure App Services using azure graph queries
We can make use of Azure Resource Graph to make cross-subscription queries to see if I have any upcoming expiring certificates.
To learn more on Azure Graph Queries, click here.
Get all web app certificates
This will get you a list of all the app service certificates you have in your subscription(s).
resources
| where type == "microsoft.web/certificates"
To simplify the overview, we can limit the properties we return:
resources
| where type == "microsoft.web/certificates"
| project resourceGroup, name, subscriptionId, properties.expirationDate, properties.thumbprint, properties.subjectName, properties.issuer
Get the Expiration Date of certificates:
resources
| where type == "microsoft.web/certificates"
| extend ExpirationDate = todatetime(properties.expirationDate)
| project ExpirationDate, resourceGroup, name, subscriptionId, properties.expirationDate, properties.thumbprint, properties.subjectName, properties.issuer
| order by ExpirationDate asc
Get the number of days until expiration:
resources
| where type == "microsoft.web/certificates"
| extend ExpirationDate = todatetime(properties.expirationDate)
| extend DaysUntilExpiration = datetime_diff("day", ExpirationDate, now())
| project DaysUntilExpiration, ExpirationDate, resourceGroup, name, subscriptionId, properties.expirationDate, properties.thumbprint, properties.subjectName, properties.issuer
| where ExpirationDate < now() + 60d
| order by DaysUntilExpiration
Group by month for easy visualization:
resources
| where type == "microsoft.web/certificates"
| extend ExpirationDate = todatetime(properties.expirationDate)
| extend ExpirationYear = getyear(ExpirationDate)
| extend ExpirationMonth = format_datetime(ExpirationDate, 'yyyy-MM')
| extend DaysUntilExpiration = datetime_diff("day", ExpirationDate, now())
| summarize count() by ExpirationMonth
| order by ExpirationMonth asc
You can also pin these results, and visualizations, to your Azure Dashboards(Private/Shared).
Use Get Started view for more queries available by default:
To know more abput Azure resource graph queries, please refer here.
Please feel free to comment for any queries!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.