I am using the Azure REST API to create metric alerts for Azure Monitor using dynamic thresholds. I have been successful at creating alerts with static thresholds, but not with dynamic thresholds.
The docs clearly show many examples of how to create with dynamic thresohlds:
https://learn.microsoft.com/en-us/rest/api/monitor/metric-alerts/create-or-update?view=rest-monitor-2018-03-01&tabs=HTTP#create-or-update-a-dynamic-alert-rule-for-single-resource
I keep getting this error back:
Error: {"code":"BadRequest","message":"Required property 'threshold' not found in JSON. Path '', line 1, position 544. Activity ID: f377d39c-d5de-49dc-9e70-df93e8f6cc41."}
The "thresohld" property should not be required because I am using DynamicTresholdCriterion.
If I do put a dummy "threshold" value then the resulting alert becomes a StaticThreshold alert, and ignores my Dynamic settings.
MetricName = "IncomingMessages"
TimeAggregation = "Total"
Operator = "LessThan"
CriterionType = "DynamicThresholdCriterion"
ThresholdSensitivity = "Medium"
Severity = 4
"criteria" = @{
"odata.type" = "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria"
"allOf" = @(
@{
"name" = "metric1"
"metricName" = $MetricName
"metricNamespace" = $metricNamespace
"operator" = $Operator
"timeAggregation" = $TimeAggregation
"failingPeriods" = @{
"numberOfEvaluationPeriods" = 4
"minFailingPeriodsToAlert" = 4
}
"criterionType" = $CriterionType
"alertSensitivity" = $ThresholdSensitivity
}
)