Azure Rest API Dynamic Thresholds Broken

Grayson Williams 25 Reputation points Microsoft Employee
2024-10-21T14:13:40.4233333+00:00

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
                    }
                )
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,473 questions
{count} votes

Accepted answer
  1. Stanislav Zhelyazkov 26,181 Reputation points MVP
    2024-10-22T06:33:11.8733333+00:00

    Hi,

    I believe the metric you are using does no support monitoring multiple resources. Supported multiple resources monitoring. In such case you can try to change odata.type to Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteric and see if that will work.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.