在Azure上使用Powershell为PipelineFailedRuns创建警报时出现错误请求错误

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

我正在使用内联脚本选项为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

当我尝试运行此create alert命令时,我收到以下错误 -

[error]异常类型:ErrorResponseException,消息:不支持目标资源ID'/subscriptions/subid/resourceGroups/rgname/providers/Microsoft.DataFactory/factories/'。代码:ResourceNotSupported,状态代码:BadRequest,Reason短语:错误的请求

powershell alert monitor azure-data-factory-2
1个回答
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

---(许多皱眉,我没有任何问题)或使用splatting。

$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
© www.soinside.com 2019 - 2024. All rights reserved.