Enable and Disable a Metric Alert with Logic Apps
Greg Bonk
81
Reputation points
I wanted to automate the enable and disable of a Metric Alert Rule and I figured using a Logic App would be a great way to do so. I'm having trouble with the updating of the enabled
property.
I can use the Logic App to get / view the alert fine.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_or_update_a_resource": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['arm']['connectionId']"
}
},
"method": "get",
"path": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ace-vm/providers/microsoft.insights/metricalerts%2FVM%20Availability",
"queries": {
"x-ms-api-version": "2018-03-01"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
.....
But when I attempt to patch the metric alert, setting enabled from true to false, I now receive a 404 error
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Create_or_update_a_resource": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['arm']['connectionId']"
}
},
"body": {
"properties": {
"enabled": false
}
},
"method": "patch",
"path": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/ace-vm/providers/microsoft.insights/metricalerts%2FVM%20Availability",
"queries": {
"x-ms-api-version": "2018-03-01"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
The Error
{
"statusCode": 404,
"headers": {
"Access-Control-Allow-Methods": "GET, PUT, PATCH, DELETE, POST",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "3600",
"Access-Control-Expose-Headers": "*",
"Date": "Thu, 09 Nov 2023 22:23:34 GMT",
"Content-Length": "54",
"Content-Type": "application/json"
},
"body": {
"statusCode": 404,
"message": "Resource not found"
}
}
I also had similar results with "Resources - Update By Id" and API version 2021-04-01
Sign in to answer