创建或更新 Application Insights Web 测试定义。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/webtests/{webTestName}?api-version=2022-06-15
URI 参数
名称 |
在 |
必需 |
类型 |
说明 |
resourceGroupName
|
path |
True
|
string
|
资源组的名称。 此名称不区分大小写。
|
subscriptionId
|
path |
True
|
string
|
目标订阅的 ID。
|
webTestName
|
path |
True
|
string
|
Application Insights WebTest 资源的名称。
|
api-version
|
query |
True
|
string
|
要用于此操作的 API 版本。
|
请求正文
名称 |
必需 |
类型 |
说明 |
location
|
True
|
string
|
资源位置
|
properties.Kind
|
True
|
WebTestKind
|
这是 Web 测试的类型,有效选项为 ping、多步骤和标准。
|
properties.Locations
|
True
|
WebTestGeolocation[]
|
一个列表,其中列出了从何处实际运行测试,以便为应用程序的可访问性提供全球覆盖。
|
properties.Name
|
True
|
string
|
如果此 WebTest,则为用户定义的名称。
|
properties.SyntheticMonitorId
|
True
|
string
|
此 WebTest 的唯一 ID。 这通常与“名称”字段的值相同。
|
kind
|
|
WebTestKind
|
此 Web 测试监视的 WebTest 类型。 选项包括 ping、多步骤和标准。
|
properties.Configuration
|
|
Configuration
|
WebTest 的 XML 配置规范。
|
properties.Description
|
|
string
|
此 WebTest 的用户定义说明。
|
properties.Enabled
|
|
boolean
|
测试是否受到主动监视。
|
properties.Frequency
|
|
integer
|
此 WebTest 的测试运行之间的间隔(以秒为单位)。 默认值为 300。
|
properties.Request
|
|
Request
|
请求属性的集合
|
properties.RetryEnabled
|
|
boolean
|
如果此 Web 测试失败,请允许重试。
|
properties.Timeout
|
|
integer
|
直到此 WebTest 超时并失败的秒数。 默认值为 30。
|
properties.ValidationRules
|
|
ValidationRules
|
验证规则属性的集合
|
tags
|
|
object
|
资源标记
|
响应
名称 |
类型 |
说明 |
200 OK
|
WebTest
|
已成功创建或更新 Application Insights Web 测试。
|
安全性
azure_auth
Azure Active Directory OAuth2 流。
类型:
oauth2
流向:
implicit
授权 URL:
https://login.microsoftonline.com/common/oauth2/authorize
作用域
名称 |
说明 |
user_impersonation
|
模拟用户帐户
|
示例
webTestCreate
示例请求
PUT https://management.azure.com/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/webtests/my-webtest-my-component?api-version=2022-06-15
{
"location": "South Central US",
"kind": "ping",
"properties": {
"Name": "my-webtest-my-component",
"SyntheticMonitorId": "my-webtest-my-component",
"Configuration": {
"WebTest": "<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"120\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>"
},
"Description": "Ping web test alert for mytestwebapp",
"Enabled": true,
"Frequency": 900,
"Timeout": 120,
"Kind": "ping",
"RetryEnabled": true,
"Locations": [
{
"Id": "us-fl-mia-edge"
}
]
}
}
import com.azure.resourcemanager.applicationinsights.models.WebTestGeolocation;
import com.azure.resourcemanager.applicationinsights.models.WebTestKind;
import com.azure.resourcemanager.applicationinsights.models.WebTestPropertiesConfiguration;
import java.util.Arrays;
/**
* Samples for WebTests CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/applicationinsights/resource-manager/Microsoft.Insights/stable/2022-06-15/examples/WebTestCreate.
* json
*/
/**
* Sample code: webTestCreate.
*
* @param manager Entry point to ApplicationInsightsManager.
*/
public static void webTestCreate(com.azure.resourcemanager.applicationinsights.ApplicationInsightsManager manager) {
manager.webTests().define("my-webtest-my-component").withRegion("South Central US")
.withExistingResourceGroup("my-resource-group").withKind(WebTestKind.PING)
.withSyntheticMonitorId("my-webtest-my-component").withWebTestName("my-webtest-my-component")
.withDescription("Ping web test alert for mytestwebapp").withEnabled(true).withFrequency(900)
.withTimeout(120).withWebTestKind(WebTestKind.PING).withRetryEnabled(true)
.withLocations(Arrays.asList(new WebTestGeolocation().withLocation("us-fl-mia-edge")))
.withConfiguration(new WebTestPropertiesConfiguration().withWebTest(
"<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"120\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.ApplicationInsights.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.ApplicationInsights;
// Generated from example definition: specification/applicationinsights/resource-manager/Microsoft.Insights/stable/2022-06-15/examples/WebTestCreate.json
// this example is just showing the usage of "WebTests_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "subid";
string resourceGroupName = "my-resource-group";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this ApplicationInsightsWebTestResource
ApplicationInsightsWebTestCollection collection = resourceGroupResource.GetApplicationInsightsWebTests();
// invoke the operation
string webTestName = "my-webtest-my-component";
ApplicationInsightsWebTestData data = new ApplicationInsightsWebTestData(new AzureLocation("South Central US"))
{
Kind = WebTestKind.Ping,
SyntheticMonitorId = "my-webtest-my-component",
WebTestName = "my-webtest-my-component",
Description = "Ping web test alert for mytestwebapp",
IsEnabled = true,
FrequencyInSeconds = 900,
TimeoutInSeconds = 120,
WebTestKind = WebTestKind.Ping,
IsRetryEnabled = true,
Locations =
{
new WebTestGeolocation()
{
Location = new AzureLocation("us-fl-mia-edge"),
}
},
WebTest = "<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"120\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>",
};
ArmOperation<ApplicationInsightsWebTestResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, webTestName, data);
ApplicationInsightsWebTestResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ApplicationInsightsWebTestData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/webtests/my-webtest-my-component",
"name": "my-webtest-my-component",
"type": "Microsoft.Insights/webtests",
"location": "southcentralus",
"tags": {
"hidden-link:/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/components/my-component": "Resource"
},
"kind": "ping",
"properties": {
"Name": "my-webtest-my-component",
"SyntheticMonitorId": "my-webtest-my-component",
"Description": "Ping web test alert for mytestwebapp",
"Enabled": true,
"Frequency": 900,
"Timeout": 120,
"Kind": "ping",
"RetryEnabled": true,
"Locations": [
{
"Id": "us-fl-mia-edge"
}
],
"Configuration": {
"WebTest": "<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"120\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>"
},
"provisioningState": "Succeeded"
}
}
webTestCreateStandard
示例请求
PUT https://management.azure.com/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/webtests/my-webtest-my-component?api-version=2022-06-15
{
"location": "South Central US",
"properties": {
"Name": "my-webtest-my-component",
"SyntheticMonitorId": "my-webtest-my-component",
"Description": "Ping web test alert for mytestwebapp",
"Enabled": true,
"Frequency": 900,
"Timeout": 120,
"Kind": "standard",
"RetryEnabled": true,
"Request": {
"RequestUrl": "https://bing.com",
"Headers": [
{
"key": "Content-Language",
"value": "de-DE"
},
{
"key": "Accept-Language",
"value": "de-DE"
}
],
"HttpVerb": "POST",
"RequestBody": "SGVsbG8gd29ybGQ="
},
"ValidationRules": {
"SSLCheck": true,
"SSLCertRemainingLifetimeCheck": 100
},
"Locations": [
{
"Id": "us-fl-mia-edge"
}
]
}
}
import com.azure.resourcemanager.applicationinsights.models.HeaderField;
import com.azure.resourcemanager.applicationinsights.models.WebTestGeolocation;
import com.azure.resourcemanager.applicationinsights.models.WebTestKind;
import com.azure.resourcemanager.applicationinsights.models.WebTestPropertiesRequest;
import com.azure.resourcemanager.applicationinsights.models.WebTestPropertiesValidationRules;
import java.util.Arrays;
/**
* Samples for WebTests CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/applicationinsights/resource-manager/Microsoft.Insights/stable/2022-06-15/examples/
* WebTestCreateStandard.json
*/
/**
* Sample code: webTestCreateStandard.
*
* @param manager Entry point to ApplicationInsightsManager.
*/
public static void
webTestCreateStandard(com.azure.resourcemanager.applicationinsights.ApplicationInsightsManager manager) {
manager.webTests().define("my-webtest-my-component").withRegion("South Central US")
.withExistingResourceGroup("my-resource-group").withSyntheticMonitorId("my-webtest-my-component")
.withWebTestName("my-webtest-my-component").withDescription("Ping web test alert for mytestwebapp")
.withEnabled(true).withFrequency(900).withTimeout(120).withWebTestKind(WebTestKind.STANDARD)
.withRetryEnabled(true)
.withLocations(Arrays.asList(new WebTestGeolocation().withLocation("us-fl-mia-edge")))
.withRequest(new WebTestPropertiesRequest().withRequestUrl("https://bing.com")
.withHeaders(Arrays.asList(
new HeaderField().withHeaderFieldName("fakeTokenPlaceholder").withHeaderFieldValue("de-DE"),
new HeaderField().withHeaderFieldName("fakeTokenPlaceholder").withHeaderFieldValue("de-DE")))
.withHttpVerb("POST").withRequestBody("SGVsbG8gd29ybGQ="))
.withValidationRules(
new WebTestPropertiesValidationRules().withSslCheck(true).withSslCertRemainingLifetimeCheck(100))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.ApplicationInsights.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.ApplicationInsights;
// Generated from example definition: specification/applicationinsights/resource-manager/Microsoft.Insights/stable/2022-06-15/examples/WebTestCreateStandard.json
// this example is just showing the usage of "WebTests_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "subid";
string resourceGroupName = "my-resource-group";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this ApplicationInsightsWebTestResource
ApplicationInsightsWebTestCollection collection = resourceGroupResource.GetApplicationInsightsWebTests();
// invoke the operation
string webTestName = "my-webtest-my-component";
ApplicationInsightsWebTestData data = new ApplicationInsightsWebTestData(new AzureLocation("South Central US"))
{
SyntheticMonitorId = "my-webtest-my-component",
WebTestName = "my-webtest-my-component",
Description = "Ping web test alert for mytestwebapp",
IsEnabled = true,
FrequencyInSeconds = 900,
TimeoutInSeconds = 120,
WebTestKind = WebTestKind.Standard,
IsRetryEnabled = true,
Locations =
{
new WebTestGeolocation()
{
Location = new AzureLocation("us-fl-mia-edge"),
}
},
Request = new WebTestRequest()
{
RequestUri = new Uri("https://bing.com"),
Headers =
{
new WebTestRequestHeaderField()
{
HeaderFieldName = "Content-Language",
HeaderFieldValue = "de-DE",
},new WebTestRequestHeaderField()
{
HeaderFieldName = "Accept-Language",
HeaderFieldValue = "de-DE",
}
},
HttpVerb = "POST",
RequestBody = "SGVsbG8gd29ybGQ=",
},
ValidationRules = new WebTestValidationRules()
{
CheckSsl = true,
SslCertRemainingLifetimeCheck = 100,
},
};
ArmOperation<ApplicationInsightsWebTestResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, webTestName, data);
ApplicationInsightsWebTestResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ApplicationInsightsWebTestData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/webtests/my-webtest-my-component",
"name": "my-webtest-my-component",
"type": "Microsoft.Insights/webtests",
"location": "southcentralus",
"tags": {
"hidden-link:/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/components/my-component": "Resource"
},
"properties": {
"Name": "my-webtest-my-component",
"SyntheticMonitorId": "my-webtest-my-component",
"Description": "Ping web test alert for mytestwebapp",
"Enabled": true,
"Frequency": 900,
"Timeout": 120,
"Kind": "standard",
"RetryEnabled": true,
"Locations": [
{
"Id": "us-fl-mia-edge"
}
],
"Request": {
"RequestUrl": "https://bing.com",
"Headers": [
{
"key": "Content-Language",
"value": "de-DE"
},
{
"key": "Accept-Language",
"value": "de-DE"
}
],
"HttpVerb": "POST",
"RequestBody": "SGVsbG8gd29ybGQ="
},
"ValidationRules": {
"SSLCheck": true,
"SSLCertRemainingLifetimeCheck": 100
},
"provisioningState": "Succeeded"
}
}
webTestUpdate
示例请求
PUT https://management.azure.com/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/webtests/my-webtest-my-component?api-version=2022-06-15
{
"location": "South Central US",
"kind": "ping",
"properties": {
"Configuration": {
"WebTest": "<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" Enabled=\"True\" CssProjectStructure=\"\" CssIteration=\"\" Timeout=\"30\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"30\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>"
},
"Frequency": 600,
"Timeout": 30,
"Locations": [
{
"Id": "us-fl-mia-edge"
},
{
"Id": "apac-hk-hkn-azr"
}
],
"Kind": "ping",
"Name": "my-webtest-my-component",
"SyntheticMonitorId": "my-webtest-my-component"
}
}
import com.azure.resourcemanager.applicationinsights.models.WebTestGeolocation;
import com.azure.resourcemanager.applicationinsights.models.WebTestKind;
import com.azure.resourcemanager.applicationinsights.models.WebTestPropertiesConfiguration;
import java.util.Arrays;
/**
* Samples for WebTests CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/applicationinsights/resource-manager/Microsoft.Insights/stable/2022-06-15/examples/WebTestUpdate.
* json
*/
/**
* Sample code: webTestUpdate.
*
* @param manager Entry point to ApplicationInsightsManager.
*/
public static void webTestUpdate(com.azure.resourcemanager.applicationinsights.ApplicationInsightsManager manager) {
manager.webTests().define("my-webtest-my-component").withRegion("South Central US")
.withExistingResourceGroup("my-resource-group").withKind(WebTestKind.PING)
.withSyntheticMonitorId("my-webtest-my-component").withWebTestName("my-webtest-my-component")
.withFrequency(600).withTimeout(30).withWebTestKind(WebTestKind.PING)
.withLocations(Arrays.asList(new WebTestGeolocation().withLocation("us-fl-mia-edge"),
new WebTestGeolocation().withLocation("apac-hk-hkn-azr")))
.withConfiguration(new WebTestPropertiesConfiguration().withWebTest(
"<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" Enabled=\"True\" CssProjectStructure=\"\" CssIteration=\"\" Timeout=\"30\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"30\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.ApplicationInsights.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.ApplicationInsights;
// Generated from example definition: specification/applicationinsights/resource-manager/Microsoft.Insights/stable/2022-06-15/examples/WebTestUpdate.json
// this example is just showing the usage of "WebTests_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "subid";
string resourceGroupName = "my-resource-group";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this ApplicationInsightsWebTestResource
ApplicationInsightsWebTestCollection collection = resourceGroupResource.GetApplicationInsightsWebTests();
// invoke the operation
string webTestName = "my-webtest-my-component";
ApplicationInsightsWebTestData data = new ApplicationInsightsWebTestData(new AzureLocation("South Central US"))
{
Kind = WebTestKind.Ping,
SyntheticMonitorId = "my-webtest-my-component",
WebTestName = "my-webtest-my-component",
FrequencyInSeconds = 600,
TimeoutInSeconds = 30,
WebTestKind = WebTestKind.Ping,
Locations =
{
new WebTestGeolocation()
{
Location = new AzureLocation("us-fl-mia-edge"),
},new WebTestGeolocation()
{
Location = new AzureLocation("apac-hk-hkn-azr"),
}
},
WebTest = "<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" Enabled=\"True\" CssProjectStructure=\"\" CssIteration=\"\" Timeout=\"30\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"30\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>",
};
ArmOperation<ApplicationInsightsWebTestResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, webTestName, data);
ApplicationInsightsWebTestResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
ApplicationInsightsWebTestData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/webtests/my-webtest-my-component",
"name": "my-webtest-my-component",
"type": "Microsoft.Insights/webtests",
"location": "southcentralus",
"tags": {
"hidden-link:/subscriptions/subid/resourceGroups/my-resource-group/providers/Microsoft.Insights/components/my-component": "Resource"
},
"kind": "ping",
"properties": {
"Name": "my-webtest-my-component",
"SyntheticMonitorId": "my-webtest-my-component",
"Description": "Ping web test alert for mytestwebapp",
"Enabled": true,
"Frequency": 600,
"Timeout": 30,
"Kind": "ping",
"RetryEnabled": true,
"Locations": [
{
"Id": "us-fl-mia-edge"
},
{
"Id": "apac-hk-hkn-azr"
}
],
"Configuration": {
"WebTest": "<WebTest Name=\"my-webtest\" Id=\"678ddf96-1ab8-44c8-9274-123456789abc\" Enabled=\"True\" CssProjectStructure=\"\" CssIteration=\"\" Timeout=\"30\" 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=\"a4162485-9114-fcfc-e086-123456789abc\" Version=\"1.1\" Url=\"http://my-component.azurewebsites.net\" ThinkTime=\"0\" Timeout=\"30\" ParseDependentRequests=\"True\" FollowRedirects=\"True\" RecordResult=\"True\" Cache=\"False\" ResponseTimeGoal=\"0\" Encoding=\"utf-8\" ExpectedHttpStatusCode=\"200\" ExpectedResponseUrl=\"\" ReportingName=\"\" IgnoreHttpStatusCode=\"False\" /></Items></WebTest>"
},
"provisioningState": "Succeeded"
}
}
定义
Configuration
WebTest 的 XML 配置规范。
名称 |
类型 |
说明 |
WebTest
|
string
|
要针对应用程序运行的 WebTest 的 XML 规范。
|
ContentValidation
内容验证属性的集合
名称 |
类型 |
说明 |
ContentMatch
|
string
|
在 WebTest 的返回中要查找的内容。 不得为 null 或为空。
|
IgnoreCase
|
boolean
|
设置此值后,ContentMatch 验证不区分大小写。
|
PassIfTextFound
|
boolean
|
如果为 true,则如果存在与 ContentMatch 字符串匹配的匹配项,将通过验证。 如果为 false,则存在匹配项时验证将失败
|
要添加到 WebTest 的标头。
名称 |
类型 |
说明 |
key
|
string
|
标头的名称。
|
value
|
string
|
标头的值。
|
Request
请求属性的集合
名称 |
类型 |
说明 |
FollowRedirects
|
boolean
|
遵循此 Web 测试的重定向。
|
Headers
|
HeaderField[]
|
要添加到 WebTest 调用的标头及其值的列表。
|
HttpVerb
|
string
|
用于此 Web 测试的 Http 谓词。
|
ParseDependentRequests
|
boolean
|
分析此 WebTest 的依赖请求。
|
RequestBody
|
string
|
使用此 Web 测试发送的 Base64 编码字符串正文。
|
RequestUrl
|
string
|
要测试的 URL 位置。
|
ValidationRules
验证规则属性的集合
名称 |
类型 |
说明 |
ContentValidation
|
ContentValidation
|
内容验证属性的集合
|
ExpectedHttpStatusCode
|
integer
|
验证 WebTest 是否返回提供的 http 状态代码。
|
IgnoreHttpStatusCode
|
boolean
|
设置后,验证将忽略状态代码。
|
SSLCertRemainingLifetimeCheck
|
integer
|
在现有 SSL 证书过期之前,仍有几天检查。 值必须为正值,并且 SSLCheck 必须设置为 true。
|
SSLCheck
|
boolean
|
检查 SSL 证书是否仍然有效。
|
WebTest
Application Insights WebTest 定义。
名称 |
类型 |
默认值 |
说明 |
id
|
string
|
|
Azure 资源 ID
|
kind
|
WebTestKind
|
ping
|
此 Web 测试监视的 WebTest 类型。 选项包括 ping、多步骤和标准。
|
location
|
string
|
|
资源位置
|
name
|
string
|
|
Azure 资源名称
|
properties.Configuration
|
Configuration
|
|
WebTest 的 XML 配置规范。
|
properties.Description
|
string
|
|
此 WebTest 的用户定义说明。
|
properties.Enabled
|
boolean
|
|
测试是否受到主动监视。
|
properties.Frequency
|
integer
|
300
|
此 WebTest 的测试运行之间的间隔(以秒为单位)。 默认值为 300。
|
properties.Kind
|
WebTestKind
|
ping
|
这是 Web 测试的类型,有效选项为 ping、多步骤和标准。
|
properties.Locations
|
WebTestGeolocation[]
|
|
一个列表,其中列出了从何处实际运行测试,以便为应用程序的可访问性提供全球覆盖。
|
properties.Name
|
string
|
|
如果此 WebTest,则为用户定义的名称。
|
properties.Request
|
Request
|
|
请求属性的集合
|
properties.RetryEnabled
|
boolean
|
|
如果此 Web 测试失败,请允许重试。
|
properties.SyntheticMonitorId
|
string
|
|
此 WebTest 的唯一 ID。 这通常与“名称”字段的值相同。
|
properties.Timeout
|
integer
|
30
|
直到此 WebTest 超时并失败的秒数。 默认值为 30。
|
properties.ValidationRules
|
ValidationRules
|
|
验证规则属性的集合
|
properties.provisioningState
|
string
|
|
此组件的当前状态,无论 是否已在定义的资源组中预配。 用户无法更改此值,但可以从中读取此值。 值将包括 Succeeded、Deploying、Canceled 和 Failed。
|
tags
|
object
|
|
资源标记
|
type
|
string
|
|
Azure 资源类型
|
WebTestGeolocation
要从中运行 WebTest 的地理位置。 必须指定一个或多个位置,以便从中运行测试。
名称 |
类型 |
说明 |
Id
|
string
|
要从其运行的 WebTest 的位置 ID。
|
WebTestKind
此 Web 测试监视的 WebTest 类型。 选项包括 ping、多步骤和标准。
名称 |
类型 |
说明 |
multistep
|
string
|
|
ping
|
string
|
|
standard
|
string
|
|