Skip to content

A simple demo on how to communicate with Azure Resource Health API

Notifications You must be signed in to change notification settings

lucasalvarezlacasa/AzureResourceHealthAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AzureResourceHealthAPI

This is a basic example created for communicating with the Azure Resource Health API. You will need to have access to http://portal.azure.com in order to register a new application and obtain the required values for this sample to work.

Before using it, go to SubscriptionHelper.cs and complete the necessary variables in there:

  1. tenantId: this is the tenant id for your organization. To retrieve it:
  • Click on Azure Active Directory.
  • Select Properties.
  • Copy the value that appears below Directory ID.

alt text

  1. appId and appKey: to obtain these values, you will need to register a new application in the Azure portal and give the corresponding permissions to it.
  • Click on Azure Active Directory.
  • Click on App Registrations and then New application registration.
  • Choose a name for your app, select Web app / API as the application type (since this is a console app) and finally complete the Sign-on URL (you can use https://localhost for this one, since it's not relevant at all). Then hit on Create.

alt text

  • Now that the application is created, you can automatically obtain the first value that we needed: appId. It's located on the top right corner.

alt text

  • Now we need to generate the secret key for our application, this is, the appKey. For this, click on Keys and generate a new one. You can select Never Expires as the duration for it. After saving, you will have one opportunity in order to copy the secret, since it won't be displayed after that anymore.

alt text

alt text

Read these two links for a deeper understanding:

  1. subscriptionId: this is the subscription you will use for getting the resource information. To find the ID, just type down the name of the subscription in the Azure portal search bar and then click on it. After that, you will get redirected to the subscription detail page where the id can be found.

alt text

  1. Permissions: none of this will work if we don't give the proper permissions to our application. For achieving it, there are three steps that need to be followed:
  • Register Microsoft.ResourceHealth as a resource provider.

    • Look for your subscription and click on it.
    • Then click on Resource providers. You will find a list with the resources that the subscription has already registered.

    alt text

    • Look for Microsoft.ResourceHealth on the top search bar. See the status of this resource provider and if it's not registered, register it.

alt text

  • Let our application have access to Windows Azure Service Management API.
    • Click on Azure Active Directory.
    • Click on App registrations.
    • Find the application that we created on step 2 and select it.
    • Click on Settings and then Required Permissions.
    • Select an API and look for Windows Azure Service Management API.

alt text

  • Select it and then click on the Delegated Permissions checkbox. Confirm the action.

alt text

  • Give Reader role to our application inside of the subscription on where it will be used.
    • Find the subscription you are using and click on Access control (IAM).
    • Click on Add, select Reader as Role and in the Select search box look for the name of the application we registered on step 2. Select it after that and hit on save.

alt text

Now you should be good to go, run the application and you will retrieve a list with the resources of the subscription that are using Resource Health as together with their status.

Thanks everybody!

About

A simple demo on how to communicate with Azure Resource Health API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages