I'm trying to automate the creation/assignment of alerts for Azure resources (specifically VMs right now, but more later) and I feel like I have everything set up properly, but I'm getting a bad request error every time. Google surprisingly didn't have much for me on this one, there doesn't seem to be a whole lot of troubleshooting documentation out there regarding this.
Here's what I have so far (I can paste to GitHub if this is too mangled in SO)
$Dim = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "Computer" -ValuestoInclude "*"
$Condition = New-AzMetricAlertRuleV2Criteria -MetricName "Percentage CPU" -DimensionSelection $dim -TimeAggregation average -Operator GreaterThan -Threshold 95
$Target = Get-AzVM -Name [ServerName]
$ActionGroup = (Get-AzActionGroup -Name "[AGName]" -ResourceGroupName "[RGName]")
$AGID = New-AzActionGroup -ActionGroupId $ActionGroup.Id
Add-AzMetricAlertRuleV2 -Name "[ServerName] CPU Above 95%" -ResourceGroupName $Target.ResourceGroupName -WindowSize 0:5 -Frequency 0:5 -TargetResourceType "Microsoft.Compute/virtualMachines" -TargetResourceScope $Target.Id -TargetResourceRegion $Target.Location -Condition $Condition -ActionGroup $AGID -Severity 0
Below is the error I get:
Add-AzMetricAlertRuleV2 : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status
code:BadRequest, Reason phrase: Bad Request
At line:8 char:1
+ Add-AzMetricAlertRuleV2 -Name "[ServerName] Above 95%" -ResourceGrou ...
Now, I figure by that it's saying something is coming up null, but it's not specifying. It just states null/empty