azurealertazure-clirulesavailability

Attach alert rule to Azure Availability test(web test) using azure cli - "microsoft.insights/webtests is not a supported platform metric namespace"


I am working on automating azure availability test/Web test (URL ping test) using azure cli. It comes with two steps

  1. Creating availability test

  2. Attaching the alert rule to created test

.

az monitor app-insights web-test create `
--location ${Region} `
--tags hidden-link:${appInsightInstanceId}=Resource `
--description "Matrix Portal Availability" `
--enabled true --frequency 900 `
--web-test-kind "standard" `
--locations Id="emea-nl-ams-azr" `
--locations Id="emea-au-syd-edge" `
--defined-web-test-name "${description}" `
--http-verb "GET"  `
--request-url "${url}" `
--retry-enabled true `
--synthetic-monitor-id "${description}" `
--timeout 120 `
--ssl-lifetime-check 100 `
--ssl-check true `
--resource-group ${ResourceGroup} `
--name "${description}" `

though this works as expected, there is no attached alert rule for the web test , hence nothing will happen once app go down. I tried to create an alert rule using below azure cli command, giving availability test resource id as the scope

az monitor metrics alert create 
--name alert3 
--resource-group "{resource group}" 
--scopes "{availablity test resource id}"
--condition "avg availabilityResults/availabilityPercentage <= 100" 
--window-size 5m 
--evaluation-frequency 1m 
--action "{action group name}"
--description "location failed"
--tags hidden-link:{app insight resource id}=Resource

But It returns "microsoft.insights/webtests is not a supported platform metric namespace" , Any solution for this would be appreciated


Solution

  • This was impossible to achieve using azure cli and had to use powershell

    $act = New-AzActionGroup -ActionGroupId "{action group resourceid}"
    $webtestcriteria = New-AzMetricAlertRuleV2Criteria -WebTest -WebTestId "{availability test resource id}" -ApplicationInsightsId "{app insight resource id}" -FailedLocationCount 2
    Add-AzMetricAlertRuleV2 -Name {Alert name} -ResourceGroupName "{resource group name}" -WindowSize 00:05:00 -Frequency 00:05:00 -TargetResourceId "{web test resource id}" -Condition $webtestcriteria -ActionGroup $act -Severity 4