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.