5
votes

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.

1

1 Answers

2
votes

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.