是否可以使用Azure CLI设置监视URL Ping测试?

是否可以使用Azure CLI设置监视URL Ping测试?,azure,azure-application-insights,azure-cli,Azure,Azure Application Insights,Azure Cli,是否可以使用Azure CLI以编程方式创建Azure Application Insights可用性URL Ping测试? 我已经查看了az cli application insights文档(此处:),但没有找到任何与创建URL Ping测试相关的内容。您可以通过部署ARM模板来完成。下面是一个模板示例。它创建可用性测试并设置警报 { "$schema": "https://schema.management.azure.com/schemas/201

是否可以使用Azure CLI以编程方式创建Azure Application Insights可用性URL Ping测试?
我已经查看了az cli application insights文档(此处:),但没有找到任何与创建URL Ping测试相关的内容。

您可以通过部署ARM模板来完成。下面是一个模板示例。它创建可用性测试并设置警报

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "webTestLocation": {
            "type": "String"
        },
        "componentName": {
            "type": "String"
        },
        "testName": {
            "type": "String"
        },
        "testEndpoint": {
            "type": "String"
        },
        "testLocations": {
            "type": "Array"
        },
        "numLocationsToAlertOn": {
            "type": "Int" 
        },
        "alertDescription": {
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "microsoft.insights/webtests",
            "apiVersion": "2015-05-01",
            "name": "[parameters('testName')]",
            "location": "[parameters('webTestLocation')]",
            "tags": {
                "[concat('hidden-link:',resourceId('microsoft.insights/components',parameters('componentName')))]": "Resource"
            },
            "properties": {
                "SyntheticMonitorId": "[parameters('testName')]",
                "Name": "[parameters('testName')]",
                "Enabled": true,
                "Frequency": 300,
                "Timeout": 120,
                "Kind": "ping",
                "RetryEnabled": false,
                "Locations": "[parameters('testLocations')]",
                "Configuration": {
                    "WebTest": "[concat('<WebTest         Name=\"',parameters('testName'),'\"         Id=\"00000000-0000-0000-0000-000000000000\"         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\"         Guid=\"a86e39d1-b852-55ed-a079-23844e235d01\"         Version=\"1.1\"         Url=\"',parameters('testEndpoint'),'\"         ThinkTime=\"0\"         Timeout=\"120\"         ParseDependentRequests=\"False\"         FollowRedirects=\"True\"         RecordResult=\"True\"         Cache=\"False\"         ResponseTimeGoal=\"0\"         Encoding=\"utf-8\"         ExpectedHttpStatusCode=\"200\"         ExpectedResponseUrl=\"\"         ReportingName=\"\"         IgnoreHttpStatusCode=\"False\" />        </Items>        </WebTest>')]"
                }
            }
        },
        {
            "type": "microsoft.insights/metricalerts",
            "name": "[parameters('testName')]",
            "apiVersion": "2018-03-01",
            "location": "global",
            "tags": {
                "[concat('hidden-link:',resourceId('microsoft.insights/components',parameters('componentName')))]": "Resource",
                "[concat('hidden-link:',resourceId('microsoft.insights/webtests',parameters('testName')))]": "Resource"
            },
            "properties": {
                "description": "[parameters('alertDescription')]",
                "enabled": true,
                "severity": 3,
                "windowSize": "PT5M",
                "evaluationFrequency": "PT1M",
                "criteria": {
                    "failedLocationCount": "[parameters('numLocationsToAlertOn')]",
                    "webTestId": "[resourceId('microsoft.insights/webtests/',parameters('testName'))]",
                    "componentId": "[resourceId('microsoft.insights/components/',parameters('componentName'))]",
                    "odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"
                },
                "actions": [
                    {
                        "actionGroupId": "[resourceId('microsoft.insights/actiongroups', 'IcM')]",
                        "webhookProperties": {}
                    }
                ],
                "scopes": [ "[resourceId('microsoft.insights/webtests/',parameters('testName'))]", "[resourceId('microsoft.insights/components/',parameters('componentName'))]" ]
            },
            "dependsOn": [
                "[resourceId('microsoft.insights/webtests', parameters('testName'))]"
            ]
        }
    ]
}

下面是使用az cli部署通用ARM模板的示例:

没有内置的cli命令来执行此操作,您可以选择使用直接调用REST API

首先,将一个
webtest.json
文件如下存储到您的powershell执行位置,例如,我的位置是PS
C:\Users\Administrator>
,我将文件存储在
C:\Users\Administrator
文件夹中

在此文件中,
centralus
是我的appinsight、
/subscriptions//resourceGroups//providers/microsoft.insights/components的位置/

在门户中签入:


不可以,您只能通过UI或rest api创建它。目前az cli没有简单的方法。这是积压工作。下面提供了一种使用az cli仍然可以执行此操作的方法。我们仅对PowerShell Az模块使用类似的方法。
  $result = New-AzResourceGroupDeployment `
    -Name $stampHealthCheckScaleTestName `
    -ResourceGroupName $appInsightsResourceGroupName `
    -Mode Incremental `
    -TemplateFile $scriptRoot\ArmTemplates\HealthCheckScaleArmTemplate.json `
    -webTestLocation $appInsightsComponentLocation `
    -componentName $appInsightsComponentName `
    -testName $stampHealthCheckScaleTestName `
    -testEndpoint "https://$($customDomainName)/healthcheckscale/status" `
    -testLocations $testLocations `
    -numLocationsToAlertOn $numLocationsToAlertOn `
    -alertDescription $alertDescription
{
  "location": "centralus",
  "kind": "ping",
  "tags": {
    "hidden-link:/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<appinsight-name>": "Resource"
  },
  "properties": {
    "Name": "joytest1",
    "SyntheticMonitorId": "joytest1-joyfun2",
"Configuration": {
      "WebTest": "<WebTest         Name=\"joytest1\"         Id=\"ec14f587-a3f6-40ac-8952-75c900e1d153\"         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\"         Guid=\"a7247e6c-29c1-2451-f4c8-78afe599253d\"         Version=\"1.1\"         Url=\"https://joyfun2.azurewebsites.net\"         ThinkTime=\"0\"         Timeout=\"120\"         ParseDependentRequests=\"False\"         FollowRedirects=\"True\"         RecordResult=\"True\"         Cache=\"False\"         ResponseTimeGoal=\"0\"         Encoding=\"utf-8\"         ExpectedHttpStatusCode=\"200\"         ExpectedResponseUrl=\"\"         ReportingName=\"\"         IgnoreHttpStatusCode=\"False\" />        </Items>        </WebTest>"
    },
    "Enabled": true,
    "Frequency": 900,
    "Timeout": 120,
    "Kind": "ping",
    "RetryEnabled": true,
    "Locations": [
      {
        "Id": "us-fl-mia-edge"
      },
      {
        "Id": "us-tx-sn1-azr"
      },
      {
        "Id": "emea-au-syd-edge"
      }
    ]
  }
}
az rest --method PUT --uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.Insights/webtests/joytest1-joyfun2?api-version=2015-05-01" --headers 'Content-Type=application/json' --body `@webtest.json