Accessing Azure Advisor using REST API

One of the cool still faily new services in Azure is the Azure Advisor feature. Azure Advisor is a service which provides insight into your subscription based upon high-availability, cost, performance or security (which is using Azure Security Center)

image

Using the UI (Portal) You can also download recommendations either using Excel or using PDF as well. However logging into each of these portal if you have multiple customers is a bit time consuming.

Luckily Azure Advisor is also accessable using the REST API, which can easily be scripted combined with Azure CLI from any linux host.

In order to use if you first need to send a POST command which will generate the recommendations, which I’m been using curl to achive

This script need two variables which is subscription and token (which is a service principal in Azure AD)

#Define variables
subscription=subscriptionid
token=$(az account get-access-token –output tsv | cut -f1)

#Generate Recommendations

curl -v –silent –request POST‘ ‘’
–url ‘https://management.azure.com/subscriptions/${subscription}/providers/Microsoft.Advisor/generateRecommendations?api-version=2017-03-31’ \
–header ‘authorization: Bearer $token’ \
–header ‘cache-control: no-cache’ \
-d “Content-Lenght: 0” -d “Accept: application/json” –stderr – | grep x-ms-request-id | cut -d “:” -f2 | sed ‘s: ::g’

#Get result from query

sec=https://management.azure.com/subscriptions/${subscription}/providers/microsoft.Security/tasks?api-version=2015-06-01-preview
# Getting Azure Security Center feedback
curl –request GET \
–url “$sec” \
–header “authorization: Bearer $token” \
–header ‘cache-control: no-cache’ | json_pp

This will return all recommendations are JSON based text which which is being image

defined using json_pp allows us to much easier parse it as JSON text and much easier allows us to parse each recommendation as a service ticket and allow the service desk to follow-up on each recommendations that is being returned.

Leave a Reply

Scroll to Top