使用 New-AzScheduledQueryRuleConditionObject 创建警报规则返回错误术语

问题描述 投票:0回答:1

我正在尝试使用 DevOps 管道和 Powershell 动态创建新的警报规则,但这真的很令人沮丧,因为文档规定可以传入一些参数,但在运行时出现以下错误:

##[错误]术语“-Operator”未被识别为 cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。

显然,Microsoft 文档指出可以将 -Operator 作为参数传递

$QueryRuleQuery = "let MinTime = ago(5m);\nAzureMetrics\n| where TimeGenerated < MinTime\n    and MetricName == \`"storage_percent\`"\n    and Maximum >= $($Threshold)\n    and (ResourceId has \`"ELASTICPOOLS\`" or ResourceId has \`"DATABASES\`")\n| project ResourceGroup, Resource, MetricName, Maximum,ResourceId\n| distinct ResourceGroup, Resource, MetricName, Maximum,ResourceId\n"
$QueryRuleScope = "/subscriptions/$($SubscriptionId)/resourcegroups/$($REDACTED.ToLower())-$($Environment.ToLower())-redacted/providers/microsoft.operationalinsights/workspaces/$($REDACTED.ToLower())-$($RegionCode.ToLower())-$($EnvironmentShort.ToLower())-redacted"
$QueryRuleCondition = New-AzScheduledQueryRuleConditionObject `
    -Query $QueryRuleQuery `
    -TimeAggregation 'Count' `
    -ResourceIdColumn 'Resource' `
    -Operator 'GreaterThanOrEqual' `
    -Threshold 10 `
    -FailingPeriodNumberOfEvaluationPeriod 1 `
    -FailingPeriodMinFailingPeriodsToAlert 1

New-AzScheduledQueryRule `
    -Name $QueryRuleName `
    -ResourceGroupName $ResourceGroupName `
    -Location $RegionCodeDatacenter `
    -ActionGroupResourceId "/subscriptions/$($SubscriptionId)/resourceGroups/$($REDACTED.ToLower())-$($Environment.ToLower())-redacted/providers/microsoft.insights/actionGroups/$($REDACTED.ToLower())-$($RegionCode.ToLower())-$($EnvironmentShort.ToLower())-redacted"
    -Description "This will trigger when an Elastic Pool or Database reaches $($Threshold) percent of maximum size"
    -DisplayName $QueryRuleName `
    -Scope $QueryRuleScope `
    -Severity $QueryRuleSeverityInt `
    -WindowSize 'P1D' `
    -EvaluationFrequency 'P1D' `
    -CriterionAllOf $QueryRuleCondition

任何指导表示赞赏

azure powershell azure-powershell azure-alerts
1个回答
0
投票

事实证明错误在我这边。我不小心传递了一些参数的注释,这导致了执行的失败。

© www.soinside.com 2019 - 2024. All rights reserved.