How do I add an action group to an ARM template for a microsoft.insights/scheduledqueryrules resource version 2021-02-01-preview

april Papajohn 1 Reputation point
2021-08-26T19:10:08.993+00:00

My template looks like this:

   {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "serviceName": {
                "defaultValue": "xxxxxx",
                "type": "String"
            },
            "applicationInsightsScope": {
                "defaultValue": "/subscriptions/28905b82-4369-4ade-90ce-c28a45c31d40/resourceGroups/zuse1-hlt-rgp-q1-caas-appinsights/providers/microsoft.insights/components/caas",
                "type": "String"
            },
            "heapThresholdInBytes": {
                "defaultValue": "33333",
                "type": "String"
            },
            "jmxMetricsName": {
                "defaultValue": "xxxxxx Heap Memory Used",
                "type": "String"
            }
        },
        "variables": {},
        "resources": [
            {
                "type": "microsoft.insights/scheduledqueryrules",
                "apiVersion": "2021-02-01-preview",
                "name": "[concat(parameters('serviceName'), ' Heap Memory Threshold Exceeded')]",
                "location": "eastus",
                "properties": {
                    "displayName": "[concat(parameters('serviceName'), ' Heap Memory Threshold Exceeded')]",
                    "description": "Alerts if the heap memory usage is meeting the threshold.",
                    "severity": 2,
                    "enabled": true,
                    "evaluationFrequency": "PT15M",
                    "scopes": [
                        "[parameters('applicationInsightsScope')]"
                    ],
                    "windowSize": "PT1H",
                    "criteria": {
                        "allOf": [
                            {
                                "query": "[concat('let heapUsedThreshold = ', parameters('heapThresholdInBytes'), ';\nlet timeGrain = 5m;\ncustomMetrics\n| where name == \"', parameters('jmxMetricsName'),'\"\n| summarize AggregatedValue=percentiles(valueSum,95)  by name, cloud_RoleName, bin(timestamp, timeGrain)\n| where AggregatedValue > heapUsedThreshold')]",
                                "timeAggregation": "Count",
                                "operator": "GreaterThanOrEqual",
                                "threshold": 6,
                                "failingPeriods": {
                                    "numberOfEvaluationPeriods": 1,
                                    "minFailingPeriodsToAlert": 1
                                }
                            }
                        ]
                    },
                    "actions": {}
                }
            }
        ]
    }

This was mostly generated from an existing alert. It is confusing that the "actions" field is an object-type instead of an array. the "actions" in an ARM template for a microsoft.insights/metricalerts version 2018-03-01 is an array. For that type I used this and it works:
"actions": [
{
"actionGroupId": "[parameters('actionGroup')]",
"webHookProperties": {}
}
]
But it results in an error if I try it with the scheduledQueryRules type. I tried this, but it doesn't work either:
"actions":
{
"actionGroupId": "[parameters('actionGroup')]",
"webHookProperties": {}
}

I generated the template from a rule that actually has an action-group associated with it, so it's odd that it's empty and didn't get generated for me.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,939 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Stanislav Zhelyazkov 21,846 Reputation points MVP
    2021-08-30T11:15:18.54+00:00

    Hi,
    The syntax for actions is the following

    ...  
     "actions": {  
      "actionGroups" : [  
         "<action Group resource id>"  
       ],  
       "customProperties": {  
           "property1": "value1",  
           "property2": "value2"  
       }  
    }  
    ...  
    

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.