I am trying to create alerts for databases in Azure using Add-AzMetricAlertRuleV2 command , but approach is working for other resources types like ASP , app services. not working with databases . can some one help me to figure it out.
$ResourceName = "s0010asq/mfwt1"
$jsonFiles = "sqlalert"
$MetricName = "storage_percent"
$MetricNamespace = "Microsoft.Sql/servers/databases"
$Operator = "GreaterThan"
$Threshold = "90.0"
$TimeAggregation = "Average"
$Actiongroup = "/subscriptions/35324-3245-3245-3425-32453452345/resourceGroups/s00149rgp/providers/microsoft.insights/actionGroups/Infra Sev4"
$WindowSize = "5"
$Frequency = "5"
$Alerts_Severity = "4"
Set-AzContext -Subscription "s00yrjfjhjjhdopdnu74" | Out-Null
$scope = (Get-AzResource -ResourceGroupName $ResourceGroupNames -Name $ResourceName).ResourceId
$alertName = "$ResourceName $MetricName High"
Write-Output "`n`n[34;1m**creating $alertName alert with template $($jsonFiles.FullName)**[0m"
$condition = New-AzMetricAlertRuleV2Criteria -MetricName $MetricName `
-MetricNamespace $MetricNamespace `
-Operator $Operator `
-Threshold $Threshold `
-TimeAggregation $TimeAggregation `
Add-AzMetricAlertRuleV2 -Name $alertName -ResourceGroupName $ResourceGroupNames `
-TargetResourceId $scope `
-ActionGroupId $Actiongroup `
-WindowSize $WindowSize `
-Frequency $Frequency `
-Condition $condition `
-Severity $Alerts_Severity `
-Description $alertName
Getting error like :
Add-AzMetricAlertRuleV2 : Exception type: ErrorResponseException, Message: Null/Empty, Code: Null, Status code:NotFound, Reason phrase: Not Found
At line:24 char:33
+ ... Add-AzMetricAlertRuleV2 -Name $alertName -ResourceGroupNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzMetricAlertRuleV2], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Alerts.AddAzureRmMetricAlertRuleV2Command
> Blockquote


