none
AI ARM Yemplate deployment RRS feed

  • Question

  • Hi

    If i want to deploy Application Insights via an ARM template as well as an Availability test, can i just add the test json to the end of the App Insights json, or do they have to be run separately? I have the templates for both, but wanted to run as one if possible.

    Thanks

    Shane

    Friday, June 7, 2019 10:01 AM

All replies

  • Hello, Shane.  Thank you for using Application Insights!

    Yes, you can combine the Application Insights resource creation and add an availability test (among other things).  You will need to merge the availability test code into the Application Insights resource creation code:

    https://docs.microsoft.com/en-us/azure/azure-monitor/app/powershell#add-an-availability-test

    Add an availability test

    This example is for a ping test (to test a single page).

    There are two parts in an availability test: the test itself, and the alert that notifies you of failures.

    Merge the following code into the template file that creates the app.

    {
        parameters: { ... // existing parameters here ...
          "pingURL": { "type": "string" },
          "pingText": { "type": "string" , defaultValue: ""}
        },
        variables: { ... // existing variables here ...
          "pingTestName":"[concat('PingTest-', toLower(parameters('appName')))]",
          "pingAlertRuleName": "[concat('PingAlert-', toLower(parameters('appName')), '-', subscription().subscriptionId)]"
        },
        resources: { ... // existing resources here ...
        { //
          // Availability test: part 1 configures the test
          //
          "name": "[variables('pingTestName')]",
          "type": "Microsoft.Insights/webtests",
          "apiVersion": "2014-04-01",
          "location": "[parameters('appLocation')]",
          // Ensure this is created after the app resource:
          "dependsOn": [
            "[resourceId('Microsoft.Insights/components', parameters('appName'))]"
          ],
          "tags": {
            "[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('appName')))]": "Resource"
          },
          "properties": {
            "Name": "[variables('pingTestName')]",
            "Description": "Basic ping test",
            "Enabled": true,
            "Frequency": 900, // 15 minutes
            "Timeout": 120, // 2 minutes
            "Kind": "ping", // single URL test
            "RetryEnabled": true,
            "Locations": [
              {
                "Id": "us-va-ash-azr"
              },
              {
                "Id": "emea-nl-ams-azr"
              },
              {
                "Id": "apac-jp-kaw-edge"
              }
            ],
            "Configuration": {
              "WebTest": "[concat('<WebTest   Name=\"', variables('pingTestName'), '\"   Enabled=\"True\"         CssProjectStructure=\"\"    CssIteration=\"\"  Timeout=\"120\"  WorkItemIds=\"\"         xmlns=\"http://microsoft.com/schemas/VisualStudio/TeamTest/2010\"         Description=\"\"  CredentialUserName=\"\"  CredentialPassword=\"\"         PreAuthenticate=\"True\"  Proxy=\"default\"  StopOnError=\"False\"         RecordedResultFile=\"\"  ResultsLocale=\"\">  <Items>  <Request Method=\"GET\"    Version=\"1.1\"  Url=\"', parameters('Url'),   '\" ThinkTime=\"0\"  Timeout=\"300\" ParseDependentRequests=\"True\"         FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\"         ResponseTimeGoal=\"0\"  Encoding=\"utf-8\"  ExpectedHttpStatusCode=\"200\"         ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" />        </Items>  <ValidationRules> <ValidationRule  Classname=\"Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleFindText, Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\" DisplayName=\"Find Text\"         Description=\"Verifies the existence of the specified text in the response.\"         Level=\"High\"  ExecutionOrder=\"BeforeDependents\">  <RuleParameters>        <RuleParameter Name=\"FindText\" Value=\"',   parameters('pingText'), '\" />  <RuleParameter Name=\"IgnoreCase\" Value=\"False\" />  <RuleParameter Name=\"UseRegularExpression\" Value=\"False\" />  <RuleParameter Name=\"PassIfTextFound\" Value=\"True\" />  </RuleParameters> </ValidationRule>  </ValidationRules>  </WebTest>')]"
            },
            "SyntheticMonitorId": "[variables('pingTestName')]"
          }
        },
    
        {
          //
          // Availability test: part 2, the alert rule
          //
          "name": "[variables('pingAlertRuleName')]",
          "type": "Microsoft.Insights/alertrules",
          "apiVersion": "2014-04-01",
          "location": "[parameters('appLocation')]", 
          "dependsOn": [
            "[resourceId('Microsoft.Insights/webtests', variables('pingTestName'))]"
          ],
          "tags": {
            "[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('appName')))]": "Resource",
            "[concat('hidden-link:', resourceId('Microsoft.Insights/webtests', variables('pingTestName')))]": "Resource"
          },
          "properties": {
            "name": "[variables('pingAlertRuleName')]",
            "description": "alert for web test",
            "isEnabled": true,
            "condition": {
              "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.LocationThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
              "odata.type": "Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition",
              "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/webtests', variables('pingTestName'))]",
                "metricName": "GSMT_AvRaW"
              },
              "windowSize": "PT15M", // Take action if changed state for 15 minutes
              "failedLocationCount": 2
            },
            "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": []
              }
            ]
          }
        }
    }

    Tuesday, June 11, 2019 1:13 AM
    Moderator
  • HI

    Thank you for the response, i will give this a go. What is meant by merge, stick the above code at the end of the template that will create the app insights resource, or merge into the main body?

    Thanks

    Shane

    Tuesday, June 11, 2019 12:27 PM