The following forum(s) have migrated to Microsoft Q&A (Preview): Azure Virtual Machines!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
How to enable diagnostics in windows VM using Azure REST API? RRS feed

  • Question

  • 1.Get access token

    You need to get Access_token to authenticate your REST call. You can get it by Azure REST API. To demonstrate how to negotiate with Azure server, here I use Restlet Client as our http tool.
    [![enter image description here][1]][1]
    Method: POST

    URL: https://login.windows.net/{DirectoryID}/oauth2/token

    Header: Content-Type: application/x-www-form-urlencoded

    Body: grant_type=client_credentials&client_id={Application ID}&client_secret={key}&resource=https://management.core.windows.net/

    You can get the DirectoryID from portal website->Azure Active Directory->properties, Application ID and key from portal website->Azure Active Directory->App registration->the application you register before.When the request succeed, you can get the Access_token:
    [![enter image description here][2]][2]
    2.Enable diagnostic by Azure REST API:

    Now you can use the Azure REST API to enable diagnostic. Below is the request you should send to Azure.
    [![enter image description here][3]][3]
    Method: PUT

    HEADERS:

        Authorization:Bearer {Access_token}
        Content-Type:application/json

    Request URI:

        https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}/extensions/IaaSDiagnostics?api-version=2016-04-30-preview

    Request BODY:

         {
         "properties": {
         "publisher": "Microsoft.Azure.Diagnostics",
         "type": "IaaSDiagnostics",
         "typeHandlerVersion": "1.5",
         "autoUpgradeMinorVersion": true,
         "settings": {
         "StorageAccount": "{storageAccountName}",
         "WadCfg": "base64(xml file)"
         },
         "protectedSettings": {
         "storageAccountName": "{storageAccountName}",
         "storageAccountKey": "{storageAccountKey}"
         }
         },
         "type": "Microsoft.Compute/virtualMachines/extensions",
         "location": "{VM region}",
         "id": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Compute/virtualMachines/{VMName}/extensions/IaaSDiagnostics",
         "name": "IaaSDiagnostics"
        }

    After successful calling of the above API, it returns 201 created and have a provisioningState field in the returned results, values are: creating. Below is the screenshot:
    [![enter image description here][4]][4]

    If you’re Microsoft partner, I find a free channel to solve azure queries: aka.ms/devchat. They support online chat and email.

      [1]: https://i.stack.imgur.com/0ztde.png
      [2]: https://i.stack.imgur.com/BrWSS.png
      [3]: https://i.stack.imgur.com/kQdFc.png
      [4]: https://i.stack.imgur.com/Txhro.png

    Thursday, October 18, 2018 2:09 AM

All replies

  • If you already solved the problem then please provide your solution in the replay and accept your own answer, Instead of putting in the question itself


    JAYENDRAN

    • Proposed as answer by Ajay-Kumar Thursday, October 18, 2018 9:40 AM
    Thursday, October 18, 2018 3:00 AM