Search code examples
azurepowershellazure-devopsmonitorazure-alerts

Enabling an azure metric alert V2


i am working on azure to monitor appservices and while a Continous deployments i am trying to build an automation task to disable/enable alert during deployments

For disabling alerts it is working

Get-AzMetricAlertRuleV2 -ResourceGroupName "<resource group name>"  -Name "<alert name>" | Add-AzMetricAlertRuleV2 -DisableRule

For enabling the alerts after the deployments

Get-AzMetricAlertRuleV2 -ResourceGroupName "<resource group name>"  -Name "<alert name>" | Add-AzMetricAlertRuleV2 -TargetResourceRegion "westeurope"

I get the following error:

Add-AzMetricAlertRuleV2: Exception type: ErrorResponseException, Message: Alert update failed. Updating from StaticThresholdCriteria and odata.type SingleResourceMultipleMetricCriteria to StaticThresholdCriteria and odata.type MultipleResourceMultipleMetricCriteria is not supported. Activity ID: ec818831-0516-44a7-92ff-cbddaa82b634., Code: BadRequest, Status code:BadRequest, Reason phrase: BadRequest

Solution

  • You should not change the region by passing -TargetResourceRegion param while enabling. Add-AzMetricAlertRuleV2 is trying add a new rule thinking that it's a new rule and failing because of the shown error message (Updating from StaticThresholdCriteria and odata.type SingleResourceMultipleMetricCriteria to StaticThresholdCriteria and odata.type MultipleResourceMultipleMetricCriteria is not supported). So just enable by without passing any other params like below.

    Get-AzMetricAlertRuleV2 -ResourceGroupName "<resource group name>"  -Name "<alert name>" | Add-AzMetricAlertRuleV2