Home > database >  Disable alert rule with empty TargetResourceRegion
Disable alert rule with empty TargetResourceRegion

Time:01-26

I am trying to disable an alert rule via powershell, but I am getting the following error:

Get-AzMetricAlertRuleV2 -ResourceGroupName "myresourcegroupname"  -Name "alertname" | Add-AzMetricAlertRuleV2 -DisableRule

Add-AzMetricAlertRuleV2: Cannot validate argument on parameter 'TargetResourceRegion'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

I have tried it without the | Add-AzMetricAlertRuleV2 -DisableRule:

Get-AzMetricAlertRuleV2 -ResourceGroupName "myresourcegroupname"  -Name "alertname"
Output:
Criteria             : {Metric1}
Actions              : {/subscriptions/subscriptionguid/resourceGroups/myresourcegroupname/providers/microsoft.insights/actionGroups/actiongroupname}
ResourceGroup        : myresourcegroupname
Description          :
Severity             : 3
Enabled              : True
Scopes               : {/subscriptions/subscriptionguid/resourceGroups/myresourcegroupname/providers/Microsoft.Sql/servers/myservername/elasticpools/myelasticpoolname}
EvaluationFrequency  : 00:01:00
WindowSize           : 00:01:00
TargetResourceType   : Microsoft.Sql/servers/elasticpools
TargetResourceRegion :
AutoMitigate         : True
LastUpdatedTime      :
IsMigrated           :
Id                   : /subscriptions/3subscriptionguid/resourceGroups/myresourcegroupname/providers/microsoft.insights/metricAlerts/alertname
Name                 : alertname
Type                 : Microsoft.Insights/metricAlerts
Location             : global
Tags                 : {}
Kind                 :
Etag                 :

My previous command was telling me that 'TargetResourceRegion' is null or empty. And that's right corresponding to the output above. But how can I disable that alert rule from powershell, with an empty TargetResourceRegion?

CodePudding user response:

We tested this in our local environment, Below statements are based on our analysis.

As per the enter image description here

  • Ran the same cmdlet, by adding the |Add-AzMetricAlertRuleV2 to disable a specific metric alert rule.

enter image description here

Updated Answer:

We have also tested this cmdlet for sql elastic pools in our local environment, using the below cmdlet we are able to disable the alert.

Get-AzMetricAlertRuleV2 -ResourceGroupName '<resourcegrp>' -Name '<AlertName>'|Add-AzMetricAlertRuleV2 -DisableRule -TargetResourceRegion " "

Here is the sample screenshot for reference:

enter image description here

  •  Tags:  
  • Related