Sunday, August 22, 2021

 

Query and templates in Azure

 

Introduction. This is continuation of the article that describes Azure services. We review some of the querying, dashboard and templates conversions available from Azure.

Description. The Azure portal allows a way to create resources, query them and display them on dashboards.  While the PowerShell automation is a great way to execute queries and leverage built-in cmdlets for Azure Resources, there are much more powerful tools with Kusto queries, Azure Resource graph explorer and dashboard elements.

Creating a dashboard for “all resources” view is as straightforward as pointing and displaying it on the Azure Portal.  It would look something like this:

When the dashboard is shared, it can be exported as a template because it can be considered just another resource. Such a resource also can be expressed in the form of Azure Resource Manager Template. The above view is a list view but in the summary view, a map can be displayed with the resources and their locations.

One of the ways in which the Azure resources can be queried is in the form of a resource graph explorer.

A sample query for an Azure Resource Graph would look like this:

Resources

| where isnotnull(zones)

| order by type asc

Here the zones is a dynamic property and hence has restrictions to its usage but there are standard properties also available.

Finally, the Azure CLI offers another way to query resources but this time from a command line:

az graph query -q "Resources | where type =~ 'Microsoft.Storage/storageAccounts' | where tags['tag with a space']=='Custom value'"

These are some of the ways queries can be written and re-used to visualize via charts and graphs.

 

Sample dashboard as Azure resource:

{

    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",

    "contentVersion": "1.0.0.0",

    "parameters": {

        "dashboards_76e30d20_4a35_476f_b80f_799a0b0e8081_name": {

            "defaultValue": "76e30d20-4a35-476f-b80f-799a0b0e8081",

            "type": "String"

        }

    },

    "variables": {},

    "resources": [

        {

            "type": "Microsoft.Portal/dashboards",

            "apiVersion": "2020-09-01-preview",

            "name": "[parameters('dashboards_76e30d20_4a35_476f_b80f_799a0b0e8081_name')]",

            "location": "eastus2",

            "tags": {

                "hidden-title": "My Dashboard"

            },

            "properties": {

                "lenses": [

                    {

                        "order": 0,

                        "parts": [

                            {

                                "position": {

                                    "x": 0,

                                    "y": 0,

                                    "rowSpan": 4,

                                    "colSpan": 6

                                },

                                "metadata": {

                                    "inputs": [

                                        {},

                                        {},

                                        {},

                                        {}

                                    ],

                                    "type": "Extension/HubsExtension/PartType/BrowseAllResourcesPinnedPart"

                                }

                            }

                        ]

                    }

                ],

                "metadata": {

                    "model": {}

                }

            }

        }

    ]

}

 

 

No comments:

Post a Comment