cicorias
6/12/2017 - 9:26 PM

Application Insights ARM Deployment

Application Insights ARM Deployment

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appInsightsName": {
            "type": "string",
            "metadata": {
                "description": "The name of the application insights to create this rules for"
            }
        },
        "webtestName": {
            "type": "string",
            "metadata": {
                "description": "The name of the liveness rule"
            }
        },
        "webtestURL": {
            "type": "string",
            "metadata": {
                "description": "The URL to perform the ping on"
            }
        },
        "location": {
            "type": "string",
            "allowedValues": [
                "eastus",
                "southcentralus",
                "northeurope",
                "westeurope"
            ],
            "metadata": {
                "description": "The location of the application insights"
            }
        },
        "sendToServiceOwners": {
            "type": "bool",
            "defaultValue": true,
            "metadata": {
                "description": "Sending alerts to the service owners"
            }
        },
        "customEmails": {
            "type": "array",
            "defaultValue": [],
            "metadata": {
                "description": "Sending alerts to custom email addresses"
            }
        }
    },
    "variables": {
        "resourceNeme": "[resourceGroup().name]",
        "subscriptionID": "[subscription().subscriptionId]",
        "livenessAlertName": "[concat(parameters('webtestName'), '-alert')]"
    },
    "resources": [
        {
            "type": "microsoft.insights/webtests",
            "name": "[parameters('webtestName')]",
            "apiVersion": "2014-04-01",
            "location": "[parameters('location')]",
            "tags": {
                "[concat('hidden-link:/subscriptions/', variables('subscriptionID'), '/resourcegroups/', variables('resourceNeme'), '/providers/microsoft.insights/components/', parameters('appInsightsName'))]" : "Resource"
            },
            "scale": null,
            "properties": {
                "SyntheticMonitorId": "[parameters('webtestName')]",
                "Name": "[parameters('webtestName')]",
                "Enabled": true,
                "Frequency": 300,
                "Kind": "ping",
                "Timeout": 120,
                "Locations": [
                    {
                        "Id": "us-tx-sn1-azr"
                    },
                    {
                        "Id": "us-il-ch1-azr"
                    },
                    {
                        "Id": "us-ca-sjc-azr"
                    },
                    {
                        "Id": "us-va-ash-azr"
                    },
                    {
                        "Id": "us-fl-mia-edge"
                    }
                ],
                "Configuration": {
                    "WebTest": "[concat('<WebTest Name=\"', parameters('webtestName'), '\" Enabled=\"True\" Timeout=\"120\" StopOnError=\"False\"> <Items> <Request Method=\"GET\" Version=\"1.1\" Url=\"', parameters('webtestURL'), '\" ThinkTime=\"0\" Timeout=\"120\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" ExpectedHttpStatusCode=\"200\" IgnoreHttpStatusCode=\"False\" /> </Items> </WebTest>')]"
                }
            }
        },
        {
            "type": "microsoft.insights/alertrules",
            "name": "[variables('livenessAlertName')]",
            "apiVersion": "2014-04-01",
            "location": "[parameters('location')]",
            "tags": {
                "[concat('hidden-link:/subscriptions/', variables('subscriptionID'), '/resourcegroups/', variables('resourceNeme'), '/providers/microsoft.insights/components/', parameters('appInsightsName'))]" : "Resource",
                "[concat('hidden-link:/subscriptions/', variables('subscriptionID'), '/resourcegroups/', variables('resourceNeme'), '/providers/microsoft.insights/webtests/', parameters('webtestName'))]" : "Resource"
            },
            "scale": null,
            "properties": {
                "name": "[variables('livenessAlertName')]",
                "isEnabled": true,
                "condition": {
                    "odata.type": "Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition",
                    "dataSource": {
                        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
                        "resourceUri": "[resourceId('microsoft.insights/webtests', parameters('webtestName'))]",
                        "metricName": "GSMT_AvRaW"
                    },
                    "windowSize": "PT5M",
                    "failedLocationCount": 3
                },
                "action": {
                    "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
                    "sendToServiceOwners": "[parameters('sendToServiceOwners')]",
                    "customEmails": "[parameters('customEmails')]"
                }
            },
            "dependsOn": [
                "[resourceId('microsoft.insights/webtests', parameters('webtestName'))]"
            ]
        }
    ]
}