简体   繁体   中英

Bad Request error while creating Alerts for PipelineFailedRuns using Powershell on Azure

I am using the inline scripting option to create an Alert for AzureDataFactory V2.

The objective is to send an automated mail when the number of pipelines failed is greater than or equal to 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

I get the following error when I attempt to run this create alert command-

[error]Exception type: ErrorResponseException, Message: The target resource id '/subscriptions/subid/resourceGroups/rgname/providers/Microsoft.DataFactory/factories/' is not supported., Code: ResourceNotSupported, Status code:BadRequest, Reason phrase: Bad Request

That error is pretty specific. It's not a PowerShell issue.

What you are doing is not valid as far as Azure is concerned. 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

So, though these are all on one line you can format them so that they are more readable.

Yet, your post format, you may have done that to make it readable for us. If you did that in you script, then that is wrong. Hence the errors. With your post, that can't be done without using the backtick mark in the formatting ---

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

--- (many frown on that, I don't have any issues with it) or use 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM