0
votes

I'm trying to configure application insights alerts using ARM templates. I have used the following for a server response time alert;

{
      "name": "[variables('responseAlertName')]",
      "type": "Microsoft.Insights/alertrules",
      "apiVersion": "2014-04-01",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('components_appinsights_name')))]": "Resource"
      },
      "properties": {
        "name": "[variables('responseAlertName')]",
        "description": "response time alert",
        "isEnabled": true,
        "condition": {
          "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
          "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
          "dataSource": {
            "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
            "resourceUri": "[resourceId('microsoft.insights/components', parameters('components_appinsights_name'))]",
            "metricName": "request.duration"
          },
          "threshold": "10",
          "windowSize": "PT5M"
        },
        "actions": [
          {
            "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
            "sendToServiceOwners": true,
            "customEmails": []
          }
        ]
      }
    }

But the issue is it's being added as a 'Classic' alert in the portal. How should the template be changed so that the alert is added as a new alert but not as a classic alert?

3
You can try the type "Microsoft.Insights/metricAlerts".Charles Xu

3 Answers

1
votes

The type "Microsoft.Insights/alertrules" is the Classic metric and Classic alerts in Azure Monitor to retire in June 2019.

You can use the new module is metric alert with the type "Microsoft.Insights/metricAlerts". See Metric Alert in the template and you will know all the properties that you can set.

For more details about the difference between Old Alert and New Alert, see Old and New alerting capabilities.

1
votes

I end up doing as following;

{
      "name": "[parameters('metricAlerts_web_response_time_alert_name')]",
      "type": "Microsoft.Insights/metricAlerts",
      "location": "global",
      "apiVersion": "2018-03-01",
      "properties": {
        "description": "web server response time",
        "severity": 3,
        "enabled": true,
        "scopes": [
          "[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
        ],
        "evaluationFrequency": "Pt1m",
        "windowSize": "Pt15m",
        "criteria": {
          "odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
          "allOf": [
            {
              "name": "iard name",
              "metricName": "requests/duration",
              "dimensions": [],
              "operator": "GreaterThan",
              "threshold": 80,
              "timeAggregation": "Average"
            }
          ]
        },
        "actions": [
          {
            "actionGroupId": "[concat('subscriptions/', subscription().subscriptionId, '/resourcegroups/', resourceGroup().name, '/providers/microsoft.insights/actionGroups/', parameters('actionGroups_alerts_name'))]"
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.Insights/actionGroups', parameters('actionGroups_alerts_name'))]",
        "[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
      ]
    },
0
votes

You could use the Migration tool from the Azure portal to migrate all your configured alerts to newer alerts. You may also refer to the sample template mentioned in this doc, or even export the template from the Azure portal to check the representation. The following template works for me:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "metricalerts_test_new_alerts_test_log_analytics_name": {
        "defaultValue": "test-new-alerts-test-log-analytics",
        "type": "String"
    },
    "webtests_test_new_alerts_test_log_analytics_externalid": {
        "defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics",
        "type": "String"
    },
    "components_test_log_analytics_externalid": {
        "defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/components/test-log-analytics",
        "type": "String"
    }
},
"variables": {},
"resources": [
    {
        "type": "microsoft.insights/metricalerts",
        "apiVersion": "2018-03-01",
        "name": "[parameters('metricalerts_test_new_alerts_test_log_analytics_name')]",
        "location": "global",
        "tags": {
            "hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/components/test-log-analytics": "Resource",
            "hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics": "Resource"
        },
        "properties": {
            "description": "[concat('Automatically created alert rule for availability test \"', parameters('metricalerts_test_new_alerts_test_log_analytics_name'), '\"')]",
            "severity": 1,
            "enabled": true,
            "scopes": [
                "[parameters('webtests_test_new_alerts_test_log_analytics_externalid')]",
                "[parameters('components_test_log_analytics_externalid')]"
            ],
            "evaluationFrequency": "PT1M",
            "windowSize": "PT5M",
            "criteria": {
                "odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"
            },
            "actions": []
        }
    }
]
}

Note: The retirement date for classic alerts migration has been extended to August 31st, 2019 from the originally announced date of June 30th, 2019.