是否可以使用Azure CLI以编程方式创建Azure Application Insights可用性URL Ping测试? 我已经检查过az cli应用程序见解文档(此处为https://docs.microsoft.com/en-us/cli/azure/ext/application-insights/monitor/app-insights/component?view=azure-cli-latest),但没有发现与创建URL Ping测试有关的任何内容。
答案 0 :(得分:1)
没有内置的cli命令可以执行此操作,您的选择是直接使用az rest
调用REST API-Web Tests - Create Or Update
。
首先,将以下.container {
padding: 5rem 0rem;
}
.img-wrapper-20 {
max-width: 20%;
margin: 0rem 1.5rem 0rem 0rem;
}
.img-wrapper-20 img:hover {
transform: scale(1.08);
}
.galp {
margin-top: 20px;
text-align: center;
font-size: 20px;
font-weight: 700;
color: black;
}
.img-dimension {
max-width:100%;
}
@media screen and (max-width: 1000px) {
.d-flex {
display:flex;
flex-direction: column;
overflow: auto;
}
.img-wrapper-20 {
max-width: 80%;
margin: 0rem 1.5rem 0rem 0rem;
}
}
@media screen and (min-width: 1000px) {
.d-flex {
display: flex;
flex-direction: row;
overflow: auto;
}
}
文件存储到您的Powershell执行位置,例如我的位置是PS webtest.json
,我将文件存储在C:\Users\Administrator>
文件夹中。
在此文件中,C:\Users\Administrator
是我的appinsight的位置,centralus
是我的appinsight的资源ID,/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.insights/components/<appinsight-name>
是ping测试的名称,{{1} }是appinsight的名称,joytest1
是您要测试的URL,请用您的值替换它们。
joyfun2
然后运行下面的命令,并替换上面的值。
https://joyfun2.azurewebsites.net
在我这边工作正常。
检查门户:
答案 1 :(得分:0)
您可以通过部署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'))]"
]
}
]
}
以下是使用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
以下是使用az cli进行通用ARM模板部署的示例:https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-cli#inline-parameters