Open source Enterprise Grafana Cloud

Azure API

Connect the Infinity data source to Azure management APIs to query subscriptions, resources, cost data, and security information.

Before you begin

  • Access to the Azure portal with permissions to create app registrations
  • Note your Azure Tenant ID

Create an Azure app registration

  1. In the Azure portal, navigate to Microsoft Entra ID > App registrations.

  2. Click New registration and create an application.

  3. Navigate to Certificates & secrets and create a new client secret.

  4. Note down the following values:

    ValueLocation
    Client IDOverview > Application (client) ID
    Client SecretCertificates & secrets > Client secrets > Value
    Tenant IDOverview > Directory (tenant) ID
  5. Navigate to API permissions and verify the app has the required permissions.

  6. Assign the app a role (for example, Reader or Monitoring Reader) on the subscriptions or resources you want to query.

Configure the data source

  1. In Grafana, navigate to Connections > Data sources.

  2. Click Add new data source and select Infinity.

  3. Expand the Authentication section and select OAuth2.

  4. Select Client Credentials as the grant type.

  5. Configure the following settings:

    SettingValue
    Client IDYour Azure app client ID
    Client SecretYour Azure app client secret
    Token URLhttps://login.microsoftonline.com/<TENANT_ID>/oauth2/token
    ScopesLeave empty
  6. Add an Endpoint parameter:

    • Key: resource
    • Value: https://management.azure.com/
  7. In Allowed hosts, enter https://management.azure.com.

  8. Click Save & test.

Query examples

List subscriptions

URL:

https://management.azure.com/subscriptions?api-version=2020-01-01

Configuration:

  • Type: JSON
  • Parser: Backend or UQL
  • Root selector: value

List resource groups

URL:

https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups?api-version=2021-04-01

UQL query:

SQL
parse-json
| scope "value"
| project "Name"="name", "Location"="location", "Provisioning State"="properties.provisioningState"

List virtual machines

URL:

https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Compute/virtualMachines?api-version=2023-03-01

UQL query:

SQL
parse-json
| scope "value"
| project "Name"="name", "Location"="location", "VM Size"="properties.hardwareProfile.vmSize", "OS"="properties.storageProfile.osDisk.osType"

Query cost data

URL:

https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.CostManagement/query?api-version=2023-03-01

Method: POST

Body (JSON):

JSON
{
  "type": "Usage",
  "timeframe": "MonthToDate",
  "dataset": {
    "granularity": "Daily",
    "aggregation": {
      "totalCost": {
        "name": "Cost",
        "function": "Sum"
      }
    }
  }
}

Provision the data source

Configure Azure OAuth2 authentication through provisioning:

YAML
apiVersion: 1
datasources:
  - name: Azure Infinity
    type: yesoreyeram-infinity-datasource
    jsonData:
      auth_method: oauth2
      oauth2:
        oauth2_type: client_credentials
        client_id: YOUR_CLIENT_ID
        token_url: https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/token
      oauthPassThru: false
      allowedHosts:
        - https://management.azure.com
    secureJsonData:
      oauth2ClientSecret: YOUR_CLIENT_SECRET

Troubleshoot

IssueCauseSolution
401 UnauthorizedInvalid or expired credentialsRegenerate client secret and update configuration
403 ForbiddenMissing role assignmentAssign Reader role to the app on the target subscription
Invalid tokenWrong token URLVerify tenant ID in the token URL
Empty responseWrong API versionCheck Azure REST API docs for the correct api-version

Additional resources