Azure-cli: metrics alert update does not seem to work

Created on 11 Jan 2019  路  16Comments  路  Source: Azure/azure-cli

Describe the bug
The update function for metrics (Alerts) does not seem to work.
I have created an alert for an Application Gateway to monitor health. When you try to update the property enabled, it returns a bad response.

To Reproduce
Steps to reproduce the behavior:

az monitor metrics alert update --name testAlert --resource-group testRG --enabled false --debug

msrest.http_logger : Response content:
msrest.http_logger : {"Code":"BadRequest","Message":"targetResourceType property is missing or invalid."}
msrest.exceptions : Operation returned an invalid status code 'BadRequest'

Expected behavior

Expected no error and portal.azure.com would reflect the changes and disable the alert mentioned above.

Environment summary
az--version: azure-cli (2.0.54)
Windows 10 - Powershell

Additional context
I have used the CLI in powershell and https://docs.microsoft.com/en-us/cli/azure/monitor/alert?view=azure-cli-latest#az-monitor-alert-update

It indicates how I used it is supposed to be correct.

Monitor Monitor - Alerts Service Attention bug

All 16 comments

@tobiasahlm could you please provide the commands you used to create the application gateway and the alert itself?

@tobiasahlm could you please provide the commands you used to create the application gateway and the alert itself?

@tjprescott The application gateway and the alert was created through the Azure portal. I will try to create a scenario with CLI commands and let you know the outcome.

I have investigated it further and have the following findings:
1) It does not matter if the application gateway is created through the Azure portal or CLI.
2) I can enable and disable alerts if I created it with the following CLI command:
az monitor metrics alert create --name TempTest --resource-group AppGWTest --condition "avg UnHealthyHostCount > 1" --description "Unhealthy!" --scopes {scope} --action {actionGroup}

However if I create the identical alert on portal.azure.com, I am not able to enable/disable the alert. Then I get the invalid property.

I ran az monitor metrics alert list --resource-group appGWTest to get the output of the two alerts. They look similar and the only difference I can see that is added from portal.azure.com is: "webhookProperties": null

`

This one works (I can enable / disable through the CLI)

{
"actions": [
{
"actionGroupId": "ZZZ",
"webhookProperties": null
}
],
"autoMitigate": null,
"criteria": {
"additionalProperties": null,
"allOf": [
{
"dimensions": [],
"metricName": "UnHealthyHostCount",
"metricNamespace": "microsoft.network/applicationgateways",
"name": "cond0",
"operator": "GreaterThan",
"threshold": 1.0,
"timeAggregation": "Average"
}
],
"odatatype": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
},
"description": "Unhealthy",
"enabled": true,
"evaluationFrequency": "0:01:00",
"id": "ZZZ",
"lastUpdatedTime": null,
"location": "global",
"name": "ToahTemp4",
"resourceGroup": "AppGWTest",
"scopes": [
"ZZZ"
],
"severity": 2,
"tags": null,
"type": "Microsoft.Insights/metricAlerts",
"windowSize": "0:05:00"
}


## This one does not work (I can't enable / disable through the CLI)

{
"actions": [
{
"actionGroupId": "XXX",
"webHookProperties": {},
"webhookProperties": null
}
],
"autoMitigate": true,
"criteria": {
"additionalProperties": null,
"allOf": [
{
"dimensions": [],
"metricName": "UnhealthyHostCount",
"metricNamespace": "Microsoft.Network/applicationGateways",
"monitorTemplateType": 8,
"name": "Metric1",
"operator": "GreaterThan",
"threshold": 1.0,
"timeAggregation": "Average"
}
],
"odatatype": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
},
"description": "Test",
"enabled": true,
"evaluationFrequency": "0:01:00",
"id": "XXX",
"lastUpdatedTime": null,
"location": "global",
"name": "TempTest",
"resourceGroup": "AppGWTest",
"scopes": [
"XXX"
],
"severity": 3,
"tags": {},
"type": "Microsoft.Insights/metricAlerts",
"windowSize": "0:05:00"
},
`

@tobiasahlm thank you for the detailed info. Just to confirm, the second alert is the one you originally created in the portal and are trying to disable via CLI?

@tjprescott Exactly. The second alert is created through the Azure portal and I am not able to disable it through the CLI. I suppose you will encounter the same issue, if you create an alert on the application gateway through the azure portal.

Seeing the same behaviour for alerts that have been created via the portal

I can reproduce this behavior. I will note that I can correctly create an alert with webhook properties in the CLI, but if I then update that object, the webhook properties are lost. I believe this is an issue with the REST API specs definition that the CLI depends on.

I have created an issue there.
https://github.com/Azure/azure-rest-api-specs/issues/5065

At the same time, I would suggest opening a support ticket in the Azure portal as that will more quickly draw the attention of the service team to this issue.

Hiya, I have just been battling the same error. Any updates or work around?

No updates. I would recommend opening a support ticket in the portal.

I already did that and the customer service told me they would write when they have an update, but it is currently not on their board to fix it. So I hope more will report this, so it become a priority.

@tobiasahlm I agree.

I have tested with the metric alert on the Appilcation Gateway and updated it from the cli. It is working fine now. I'm using cli version(2.0.69)
CLI Command: az monitor metrics alert update --name testgateway --resource-group ABKASERA-RG --description abcxyz --debug

Response payload:
{
"actions": [
{
"actionGroupId": "/subscriptions/a2d51762-a47c-4358-9048-e04041599027/resourcegroups/abkasera-rg/providers/microsoft.insights/actiongroups/testactiongroup",
"webhookProperties": null
}
],
"autoMitigate": true,
"criteria": {
"additionalProperties": null,
"allOf": [
{
"dimensions": [],
"metricName": "Throughput",
"metricNamespace": "Microsoft.Network/applicationGateways",
"name": "Metric1",
"operator": "GreaterThan",
"threshold": 100.0,
"timeAggregation": "Total"
}
],
"odatatype": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
},
"description": "abcxyz",
"enabled": false,
"evaluationFrequency": "0:01:00",
"id": "/subscriptions/a2d51762-a47c-4358-9048-e04041599027/resourceGroups/ABKASERA-RG/providers/Microsoft.Insights/metricAlerts/testgateway",
"lastUpdatedTime": null,
"location": "global",
"name": "testgateway",
"resourceGroup": "ABKASERA-RG",
"scopes": [
"/subscriptions/a2d51762-a47c-4358-9048-e04041599027/resourceGroups/ABKASERA-RG/providers/Microsoft.Network/applicationGateways/testappgateway"
],
"severity": 3,
"tags": {},
"type": "Microsoft.Insights/metricAlerts",
"windowSize": "0:05:00"
}

@tobiasahlm can you let us know if you are still seeing this issue? We have not been able to repro this with the latest cli version(2.0.69)

@snehitm - It seems to work now, thanks for the update.

Thanks, @tobiasahlm. Good to know the issue is resolved and sorry for the inconvenience in the past.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kannaj picture Kannaj  路  3Comments

oakeyc picture oakeyc  路  3Comments

seanknox picture seanknox  路  3Comments

idkjs picture idkjs  路  3Comments

ambakshi picture ambakshi  路  3Comments