Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure PowerShell Add-AlertRule Returns Bad Request when using CpuPercentage on Resource Group

I get an Azure Resource Group and try to add a Metric Alert rule of type CPUPercentage, but it fails with BadRequest.

> $r = Get-AzureRmResourcegroup
WARNING: The output object of this cmdlet will be modified in a future release.
> $a = $r[0]
> Add-AlertRule -Location "West US" -MetricName CpuPercentage -Name CPU98Percent -Operator GreaterThanOrEqual -ResourceGroup $a.ResourceGroupName -ResourceId $a.ResourceId -RuleType Metric -Threshold 98
Add-AlertRule : BadRequest:
At line:1 char:1
+ add-alertrule -Location "West US" -metricName CpuPercentage -Name CPU ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-AlertRule], CloudException
    + FullyQualifiedErrorId : Hyak.Common.CloudException,Microsoft.Azure.Commands.Insights.Alerts.AddAlertRuleCommand

It works fine from the portal. There isn't already an alert with the same name either. I'm using version 1 of the Azure module and version 1.0.2 of AzureRM.

like image 310
TylerHam Avatar asked Oct 31 '22 16:10

TylerHam


1 Answers

I was receiving the same error when the alert name was not unique across all databases on the Sql Server. That is, I had multiple databases on the same server and was trying to create a rule named "DTU Percentage", which would fail after the first one was created. Once a unique name ("DTU Percentage DB_NAME") was used, the alerts were created.

Unfortunately, it sounds like you are experiencing another issue. Just thought I would add this answer for anyone searching for similar errors.

like image 91
Don Lockhart Avatar answered Nov 11 '22 18:11

Don Lockhart