azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

metrics alert update does not seem to work

Open tobiasahlm opened this issue 7 years ago • 16 comments

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.

tobiasahlm avatar Jan 11 '19 14:01 tobiasahlm

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

tjprescott avatar Jan 11 '19 23:01 tjprescott

@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.

tobiasahlm avatar Jan 14 '19 09:01 tobiasahlm

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 avatar Jan 14 '19 13:01 tobiasahlm

@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 avatar Jan 14 '19 16:01 tjprescott

@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.

tobiasahlm avatar Jan 14 '19 16:01 tobiasahlm

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

asos-wesleykey avatar Jan 17 '19 14:01 asos-wesleykey

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

tjprescott avatar Jan 18 '19 17:01 tjprescott

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.

tjprescott avatar Jan 18 '19 19:01 tjprescott

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

osariel avatar Feb 14 '19 18:02 osariel

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

tjprescott avatar Feb 14 '19 18:02 tjprescott

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 avatar Feb 15 '19 12:02 tobiasahlm

@tobiasahlm I agree.

tjprescott avatar Feb 15 '19 14:02 tjprescott

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" }

abkasera avatar Jul 17 '19 13:07 abkasera

@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)

snehithm avatar Jul 17 '19 13:07 snehithm

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

tobiasahlm avatar Jul 19 '19 09:07 tobiasahlm

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

snehithm avatar Jul 19 '19 09:07 snehithm