我希望创建DTU警报规则,监控DTU在过去15分钟内超过90%。我想对资源组中的所有数据库执行此操作。 我们的想法是自动化工作并在GUI中手动创建许多规则,并避免为每个警报运行一个脚本。它必须基本上为资源组中的数据库创建相同的警报但是提供一个独特的名称,请参阅"这必须是独一无二的"部分在剧本
我写的脚本是:
Sub loops()
Dim n_height, n_width, c As Integer
With ThisWorkbook.Sheets("Sheet1")
n_height = .Cells(Rows.Count, 1).End(xlUp).Row 'Assuming height is in column A
n_width = .Cells(Rows.Count, 2).End(xlUp).Row 'Assuming width is in column B
c = 2
For i = 2 To n_height
For j = 2 To n_width
.Range("D" & c).Value = .Range("A" & i).Value 'Prints heights in column D
.Range("E" & c).Value = .Range("B" & j).Value 'Prints widths in column E
c = c + 1
Next j
Next i
End With
End Sub
问题是,IT只创建一个ALERT,然后出现以下错误(可能会指出-name值不唯一的问题):
#define variable for resource group name by requesting keynoard input
$rg = Read-Host 'Please, input resource group name here (exactly as it is in Azure)'
<#create the array containing databases where alerts are required. The value of v12.0,user corresponds to the kind of resource as to include only the SQL DBs and not the SQL servers#>
$resources = Get-AzureRmResource | ?{ $_.ResourceGroupName -eq $rg -and $_.kind -eq "v12.0,user" } | select -expandpropert resourceid
#loop through the array and create the alert rule for each DB
foreach($resource in $resources){Add-AzureRMMetricAlertRule -ResourceGroup $rg -location "Central US" -targetresourceid $resource -Name "THAT MUST BE UNIQUE" -MetricName "dtu_consumption_percent" -Operator "GreaterThan" -Threshold 90 -WindowSize $([TimeSpan]::Parse("00:15:00")) -TimeAggregationOperator "Average" -verbose -Actions $(New-AzureRmAlertRuleEmail -SendToServiceOwners -CustomEmails "putemail@here.com")}
您能告诉我出现了什么问题吗?如何根据参数构成脚本为资源组中的每个数据库创建DTU指标?我也很好奇如何填充&#34 ; Add-AzureRMMetricAlertRule : Exception type: ErrorResponseException, Message: Can not update target resource id during
update., Code: BadRequest, Status code:BadRequest, Reason phrase: Bad Request
At C:\Users\CreateDTUalertsFORallDBv2.ps1:11 char:34
+ ... $resources){Add-AzureRMMetricAlertRule -ResourceGroup $rg -location " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzureRmMetricAlertRule], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Alerts.AddAzureRmMetricAlertRuleCommand
&#34;来自上述脚本的参数,其中包含警报将在其中工作的数据库的唯一内容(理想情况下,可以从脚本中的foreach循环之前的Get-AzureRmResource命令行开关中提供资源名称值)。
如果我尝试使用以下脚本使用DB的RESOURCENAME填充-name参数:
-name
关于名称不唯一的错误,请参阅以下错误:
#define variable for resource group name by requesting keynoard input
$rg = Read-Host 'Please, input resource group name here (exactly as it is in Azure)'
#create the array containing databases where alerts are required
$resources = Get-AzureRmResource | ?{ $_.ResourceGroupName -eq $rg -and $_.kind -eq "v12.0,user" } | select -expandpropert resourceid
#loop through the array and create the alert rule for each DB
foreach($resource in $resources){$resourcename = (Get-AzureRmResource -ResourceGroupName $rg -Resourceid $resource).resourcename;Add-AzureRMMetricAlertRule -ResourceGroup $rg -location "Central US" -targetresourceid $resource -Name $resourcename -MetricName "dtu_consumption_percent" -Operator "GreaterThan" -Threshold 90 -WindowSize $([TimeSpan]::Parse("00:15:00")) -TimeAggregationOperator "Average" -verbose -Actions $(New-AzureRmAlertRuleEmail -SendToServiceOwners -CustomEmails "Client-DestinationHotels@hhogdev.com")}
答案 0 :(得分:0)
provided.
答案 1 :(得分:-1)
您尝试创建的确切DTU提醒已在this文章上逐步创建。