Search code examples
azureazure-cli

Using the Azure cli to automate the creation of Diagnostic Settings for resources


Method:

az monitor diagnostic-settings create --resource $resourceId -n $name --event-hub $eventHub --logs '[ { "category": "WorkflowRuntime", "enabled": true, "retentionPolicy": { "enabled": false, "days": 0 } } ]' --metrics '[ { "category": "WorkflowRuntime", "enabled": true, "retentionPolicy": { "enabled": false, "days": 0 } } ]

Expectation

Creates a Diagnostic setting for the specified resource as identified by the resourceId

Actual

(BadRequest) Metric category 'WorkflowRuntime' is not supported, supported categories are: 'Capacity;Transaction'.

Solution

  • According to the error, the resource does not have the log category. In fact, the different resource type has different log categories. For more details, please refer to here.

    enter image description here

    If you want to get available categories for one resource, you can use the following command

    az monitor diagnostic-settings categories list --resource <resource id>