我正在使用内联脚本选项为AzureDataFactory V2创建警报。
目标是在失败的管道数量大于或等于1时发送自动邮件。
Add-AzureRmMetricAlertRule
-Name "SS Rule"
-Location "East US"
-ResourceGroup "RGname"
-Operator GreaterThanOrEqual
-Threshold 1
-TargetResourceId "/subscriptions/subid/resourceGroups/RGname/providers/Microsoft.DataFactory/factories/DFname"
-MetricName "PipelineFailedRuns"
-TimeAggregationOperator Total
当我尝试运行此创建警报命令时收到以下错误-
[错误]异常类型:ErrorResponseException,消息:目标 资源ID '/subscriptions/subid/resourceGroups/rgname/providers/Microsoft.DataFactory/factories/' 不支持。,代码:ResourceNotSupported,状态代码:BadRequest, 原因短语:错误的请求
答案 0 :(得分:0)
该错误非常具体。这不是PowerShell的问题。
就Azure而言,您正在做的事情是无效的。 The help file examples shows...
Example 1: Add a metric alert rule to a website
PS C:\>Add-AzureRMMetricAlertRule -Name "metricRule5" -Location "East US" -ResourceGroup "Default-Web-EastUS" -Operator GreaterThan -Threshold 2 -WindowSize 00:05:00 -MetricName "Requests" -Description "Pura Vida" -TimeAggregationOperator Total
RequestId StatusCode
--------- ----------
33574ccf-0b01-43b4-aa97-87e6bbcf1c11
Example 3: Add a rule with actions
PS C:\>Add-AzureRmMetricAlertRule -Name "metricRule5" -Location "East US" -ResourceGroup "Default-Web-EastUS" -Operator GreaterThan -Threshold 1 -TargetResourceId "/subscriptions/b93fb07a-6f93-30be-bf3e-4f0deca15f4f/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/mywebsite" -MetricName "Requests" -TimeAggregationOperator Total
RequestId StatusCode
--------- ----------
9a5bc388-c7ac-4dc6-aa70-f4bc29c2c712 OK
因此,尽管它们全部都在一行上,但是您可以对其进行格式化,以使其更具可读性。
但是,您的帖子格式可能已使我们可读。如果您在脚本中这样做,那是错误的。因此,错误。对于您的帖子,如果不使用格式---
中的反引号,则无法完成此操作Add-AzureRmMetricAlertRule -Name "SS Rule" `
-Location "East US" `
-ResourceGroup "RGname" `
-Operator GreaterThanOrEqual `
-Threshold 1 `
-TargetResourceId "/subscriptions/subid/resourceGroups/RGname/providers/Microsoft.DataFactory/factories/DFname" `
-MetricName "PipelineFailedRuns" `
-TimeAggregationOperator Total
---(对此我很皱眉,我没有任何问题)或使用喷溅。
$addAzureRmMetricAlertRuleSplat = @{
MetricName = "PipelineFailedRuns"
TimeAggregationOperator = 'Total'
ResourceGroupName = "RGname"
Operator = 'GreaterThanOrEqual'
Name = "SS Rule"
Threshold = 1
Location = "East US"
TargetResourceId = "/subscriptions/subid/resourceGroups/RGname/providers/Microsoft.DataFactory/factories/DFname"
}
Add-AzureRmMetricAlertRule @addAzureRmMetricAlertRuleSplat