Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a webtest with new alert in azure resource template?

With the classic alert migration to new alert.

I have a ping url "Microsoft.Insights/webtest" in Azure Availability Tests.

The old alert type is "Microsoft.Insights/alertrules".

The condition type is "Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition".

The old metricName is "GSMT_AvRaW".

How to write this new alert(Near-realtime) in arm or how to write into webtests in arm?

When I add New Test in Availability, I can switch Alert Type Classic to Near-realtime.It will generate a Alert

AddNewTestAlert

And I can't add New Alert condition for the webtest, I can only Click the edit alert button to Edit the Alert. Because no Metric Type can be chosen in Condition when I add new Alert.

like image 282
HaibaraAi Avatar asked Dec 23 '22 01:12

HaibaraAi


1 Answers

If you look at Resource Explorer and navigate to a manually created (near-realtime) alert, you should see the "critera" object defined like below. Here is a full example of a resource that seems to be working. Create some variables for each of your values:

{
  "type": "Microsoft.Insights/metricAlerts",
  "apiVersion": "2018-03-01",
  "name": "[variables('alertName')]",
  "location": "global",
  "dependsOn": [],
  "tags": {
    "[concat('hidden-link:', variables('applicationInsightsResourceId'))]": "Resource",
    "[concat('hidden-link:', variables('webtestResourceId'))]": "Resource"
  },
  "properties": {
    "description": "[concat('Alert for ', parameters('availibilityTestName'))]",
    "severity": 4,
    "enabled": true,
    "scopes": [
      "[variables('webtestResourceId')]",
      "[variables('applicationInsightsResourceId')]"
    ],
    "evaluationFrequency": "PT5M",
    "windowSize": "PT15M",
    "criteria": {
      "odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria",
      "webTestId": "[variables('webtestResourceId')]",
      "componentId": "[variables('applicationInsightsResourceId')]",
      "failedLocationCount": 3
    },
    "actions": [
      {
        "actionGroupId": "[resourceId('microsoft.insights/actiongroups', 'webhook')]",
        "webHookProperties": {
           // Some properties to send to webhook
        }
      }
    ]
  }
}
like image 117
Kipp Avatar answered Feb 15 '23 22:02

Kipp