Create a workbook that queries your resources

Completed

Workbooks provide a canvas for creating interactive visual reports. In this exercise, you'll create a new workbook, add some descriptive text and a parameter to query all of the resources in a selected subscription. By the end of this unit, you'll have a report that shows the distribution of your resources on a map.

Deploy resources for the exercise using the Azure CLI

The first thing we'll do is activate the Azure sandbox and deploy an ARM template containing all the Azure resources we need for this exercise.

  1. Activate the Azure sandbox. When the sandbox is activated, a resource group with the name learn-{guid} is created for you to use. This resource group will be visible in the Azure portal, or through CLI commands such as az group list.

  2. In the Azure Cloud Shell, get the name of the resource group that was generated for your sandbox.

    az group list
    
  3. The output contains a row with the name of the resource group. The name starts with "learn-".

    Screenshot of Cloud Shell displaying resource group name for sandbox.

  4. Copy the name of the resource group by right-clicking on the name and selecting Copy.

  5. Enter this command to define the resource group. (Right-click and select Paste to paste the resource group name. You may have to remove any extra characters around the resource group name.)

    resourceGroup="<your resource group name>"
    
  6. Run these commands to deploy the Azure resource group and resources:

       git clone https://github.com/MicrosoftDocs/ms-learn-azure-monitor-workbooks.git 
       cd ms-learn-azure-monitor-workbooks/Resources/
       az deployment group create --resource-group $resourceGroup --template-file deploy-resources.bicep
    
  7. When you're prompted for a password, enter a password that complies with the password requirements. For example, enter "Learn@123456". The password must:

    • Be at least 12 characters long
    • Contain at least 3 out of the following four characteristics:
      • one lower case letter
      • one upper case letter
      • one number
      • one special character, not including \ or -.
  8. Wait while the resources that you need for the module are deployed. This will take a few minutes.

  9. You can sign into the Azure portal to see the resources deployed in your sandbox for this learn module.

  10. On the Home page, select Resource groups, or search for "Resource groups" in the search bar at the top of the page.

  11. Select the "learn" resource group created when the sandbox was activated.

  12. Look through the list of resources and see the resources created for this exercise.

    Screenshot of the resources in a resource group.

Create a new workbook

  1. From the Azure portal home page, search for and select Monitor.

  2. Select Workbooks from the left pane.

  3. Select + New from the top toolbar. Screenshot that shows the New workbook icon Azure Workbooks page.

  4. Add descriptive text to the top of the workbook:

    1. Select Add and then Add Text.

      Screenshot that shows the Add text button in an Azure workbook.

    2. The Azure Workbook text editor uses markdown format. Enter text into the editor. You can copy this text if you would like.

          # Learn module exercise workbook
          **Select a subscription from the drop-down below.**
      
    3. Select Done editing. You now have a simple workbook with text.

    Screenshot of a new Azure workbook with text.

Add a subscription picker to your workbook

  1. Select Edit from the right side of the section you created.

    Screenshot that shows the edit button from a section of a workbook.

  2. Select Add, and then Add parameters.

    Screenshot that shows the add parameters button in a workbook.

  3. Select Add Parameter.

  4. In the New Parameter window:

    1. In both the Parameter name and Display name fields, enter "Subscription".
    2. In the Parameter type field, select Subscription picker.
    3. Select the Required checkbox.

    Screenshot that shows the parameter settings in a workbook.

    1. Select Save, and then Done editing.
  5. Select Done editing again. You now have a workbook with a Subscription drop-down picker.

    Screenshot that shows an Azure workbook with a subscription picker drop-down list.

Add a map to show the distribution of the subscription's resources

  1. Select Edit from the top toolbar.

  2. Select the subscription from the Subscription drop-down.

  3. Select Add Query.

    Screenshot that shows the add query icon in a workbook.

  4. In the Data source field, select Azure Resource Graph.

  5. In the Subscription field, under Resource parameters, select the Subscription checkbox.

  6. Add this query to the Subscriptions Azure Resource Graph Query section:

        resources
       | summarize count() by location
    

    Screenshot that shows a query being configured in a workbook.

  7. Select Run Query.

  8. You'll see the results of your query in a table below the query.

  9. To show your resources in a map, in the Visualization field on top of the query, select Map.

  10. In the Map Settings window, keep the default map settings, and select Save and close.

  11. Select Advanced settings at the top of the query, and enter "Resource distribution per region" in the Chart title.

  12. Select Done editing. You now have a workbook that lets the user select a subscription and displays all of the resources in that subscription in a map.

    Screenshot that shows an Azure workbook with a map displaying a subscription's resources.

  13. Select Save As.

  14. Enter a Name for your workbook, select the Subscription and Resource group, and select Apply.