Reputation: 1956
I have setup an alert in the Azure portal for the average response time metric. Now I want to automate it so that this alert gets setup on each new deploy. When I go to the Automation script tab under my resource group I can see that the alert metric has been added, but I can't find the alert criteria parameters, does anyone know where they are defined?
I have found this resource in the docs, which I have followed.
This part I can see in my automation script
"resources": [
{
"comments": "Generalized from resource: '/subscriptions/XXX/resourceGroups/resourcegroup-dev-weu/providers/microsoft.insights/metricAlerts/response-time-avg'.",
"type": "microsoft.insights/metricAlerts",
"name": "[parameters('metricAlerts_response_time_avg_name')]",
"apiVersion": "2018-03-01",
"location": "global",
"tags": {},
"scale": null,
"properties": {
"description": "Alert if the response time get above 1 second on average for the last 1 minute, 1 minute intervals.",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/XXX/resourceGroups/resourcegroup-dev-weu/providers/Microsoft.Web/sites/webapp-dev-weu"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
},
"actions": [
{
"actionGroupId": "[parameters('metricAlerts_response_time_avg_actionGroupId')]",
"webHookProperties": {}
}
]
},
"dependsOn": []
}
]
But this part I can't find
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"alertName": {
"value": "New Metric Alert"
},
"alertDescription": {
"value": "New metric alert created via template"
},
"alertSeverity": {
"value":3
},
"isEnabled": {
"value": true
},
"resourceId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourceGroup-name/providers/Microsoft.Compute/virtualMachines/replace-with-resource-name"
},
"metricName": {
"value": "Percentage CPU"
},
"operator": {
"value": "GreaterThan"
},
"threshold": {
"value": "80"
},
"timeAggregation": {
"value": "Average"
},
"actionGroupId": {
"value": "/subscriptions/replace-with-subscription-id/resourceGroups/resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group"
}
}
}
I get this error when I try to run it without the parameters defined:
New-AzureRmResourceGroupDeployment : 17:07:53 - Resource microsoft.insights/metricAlerts 'response-time-avg' failed with message '{
"Code": "BadRequest",
"Message": "Unable to find any of the requested metrics ''"
}'
Upvotes: 1
Views: 967
Reputation: 28294
I can create an alert for a VM following your providing DOC via just replacing with the values of resourceId and actionGroupId in the parameter file. Deploy the template file and parameter file with PowerShell successfully.
After that, you can see the resource type microsoft.insights/metricAlerts
in the Automation script tab. Once you create an alert, you can see the criteria properties and criteria parameter refer to the followings.
If you want to export the specific alert template instead of all resources in your current group. You can refer to these steps: Go to the Resource group page-under Settings-Deployments-Click the newly created alert deployment name. You will find the resources and parameters in the template and just download it. Get more details for viewing template.
With the same deployment as above, I can see the more of criteria parameters using the Azure REST API as below. It seems that the automation tab does not show all the necessary info. The only way to get the full automation script is to use the Azure REST API to get Metric Alerts.
Upvotes: 2