question

aprilPapajohn-9048 avatar image
0 Votes"
aprilPapajohn-9048 asked stan commented

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

stan avatar image
0 Votes"
stan answered stan commented

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.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Using the schema 2021-02-01-preview in early June this year, we used the 'actionGroupId' key to deploy alerts successfully, mapping them to our alert group e.g:

"actions": {
"actionGroupId" : [
"<action Group resource id>"
],

However this now fails with an error: ##[error]BadRequest: Alert rule payload cannot be empty

Switching over to the above solution works e.g. "actionGroups", so why has this changed if we are using the same schema version? Like the OP, when looking at the export template for the alert, the actions section is empty!

Any idea why we have seen this behaviour recently?

0 Votes 0 ·

Hi,
First please mark the provided solution as answer. I do not exact reasons but may be 2021-02-01-preview was published too early before the actual changes to that API were made. As you can see from this announcement Public preview: Azure Monitor Scheduled Query Rules API 2021-02-01-preview previous version that had this syntax was deprecated thus they have released a new version which has a slight change in the syntax compared to the previous. The slight change is in the actions section.


0 Votes 0 ·

How can we provide a custom email subject for alerts? In the Azure Portal when editing an alert rule we can customize the action - under the "Customize actions" section there is an "Email subject" checkbox with a tooltip "Check this option to override subject line of the email fired when this alert is fired". When I generated the ARM template for my alert with this subject set, nothing was generated in the template for this. Any idea how to set this using "scheduledqueryrules@2021-02-01-preview" or newer? Can it be set using a customProperties here, perhaps?

0 Votes 0 ·
stan avatar image stan JasonPaape-0114 ·

Hi, when you have question please post a new one instead of commenting on existing one. There are two type of Log Alerts - Log Alert V1 and Log Alert V2. The portal experience still creates Log Alert V1 as V2 is still in preview. Ability to have custom e-mail subject is only in v1 and not available in v2. Custom properties are available in V2 but they are only visible in the alert payload when used with automation tools like webhook, logic app, etc. V2 uses api 2021-02-01-preview and v1 2018-04-16. When you do template export v1 alerts are interpenetrated with API version 2021-02-01-preview. That is probably a bug and you can log official support request to Azure for this.

0 Votes 0 ·