建立或更新 Application Insights Web 測試定義。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/webtests/{webTestName}?api-version=2022-06-15
URI 參數
名稱 |
位於 |
必要 |
類型 |
Description |
resourceGroupName
|
path |
True
|
string
|
資源群組的名稱。 名稱不區分大小寫。
|
subscriptionId
|
path |
True
|
string
|
目標訂用帳戶的標識碼。
|
webTestName
|
path |
True
|
string
|
Application Insights WebTest 資源的名稱。
|
api-version
|
query |
True
|
string
|
用於此作業的 API 版本。
|
要求本文
名稱 |
必要 |
類型 |
Description |
location
|
True
|
string
|
資源位置
|
properties.Kind
|
True
|
WebTestKind
|
這是 Web 測試的類型,有效的選擇是 ping、多步驟和標準。
|
properties.Locations
|
True
|
WebTestGeolocation[]
|
實際執行測試的來源清單,以提供應用程式輔助功能的全域涵蓋範圍。
|
properties.Name
|
True
|
string
|
如果使用者定義名稱,則為這個 WebTest。
|
properties.SyntheticMonitorId
|
True
|
string
|
此 WebTest 的唯一標識碼。 這通常與 [名稱] 欄位相同。
|
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
|
允許重試此 WebTest 失敗。
|
properties.Timeout
|
|
integer
|
此 WebTest 的逾時和失敗前的秒數。 預設值為 30。
|
properties.ValidationRules
|
|
ValidationRules
|
驗證規則屬性的集合
|
tags
|
|
object
|
資源標籤
|
回應
名稱 |
類型 |
Description |
200 OK
|
WebTest
|
已成功建立或更新 Application Insights Web 測試。
|
安全性
azure_auth
Azure Active Directory OAuth2 Flow。
類型:
oauth2
Flow:
implicit
授權 URL:
https://login.microsoftonline.com/common/oauth2/authorize
範圍
名稱 |
Description |
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 組態規格。
名稱 |
類型 |
Description |
WebTest
|
string
|
要針對應用程式執行的 WebTest XML 規格。
|
ContentValidation
內容驗證屬性的集合
名稱 |
類型 |
Description |
ContentMatch
|
string
|
在 WebTest 的傳回中尋找的內容。 不得為 Null 或空白。
|
IgnoreCase
|
boolean
|
設定時,這個值會使 ContentMatch 驗證大小寫不區分。
|
PassIfTextFound
|
boolean
|
若為 true,如果 ContentMatch 字串符合,則驗證會通過。 如果為 false,如果相符項目,驗證將會失敗
|
要新增至 WebTest 的標頭。
名稱 |
類型 |
Description |
key
|
string
|
標頭的名稱。
|
value
|
string
|
標頭的值。
|
Request
要求屬性的集合
名稱 |
類型 |
Description |
FollowRedirects
|
boolean
|
請遵循此 Web 測試的重新導向。
|
Headers
|
HeaderField[]
|
要新增至 WebTest 呼叫的標頭及其值清單。
|
HttpVerb
|
string
|
要用於此 Web 測試的 Http 動詞。
|
ParseDependentRequests
|
boolean
|
剖析此 WebTest 的相依要求。
|
RequestBody
|
string
|
以此 Web 測試傳送的 Base64 編碼字串本文。
|
RequestUrl
|
string
|
要測試的URL位置。
|
ValidationRules
驗證規則屬性的集合
名稱 |
類型 |
Description |
ContentValidation
|
ContentValidation
|
內容驗證屬性的集合
|
ExpectedHttpStatusCode
|
integer
|
驗證 WebTest 是否傳回提供的 HTTP 狀態代碼。
|
IgnoreHttpStatusCode
|
boolean
|
設定時,驗證會忽略狀態代碼。
|
SSLCertRemainingLifetimeCheck
|
integer
|
在現有 SSL 憑證到期之前,仍要檢查的天數。 值必須是正數,且 SSLCheck 必須設定為 true。
|
SSLCheck
|
boolean
|
檢查 SSL 憑證是否仍然有效。
|
WebTest
Application Insights WebTest 定義。
名稱 |
類型 |
預設值 |
Description |
id
|
string
|
|
Azure 資源標識碼
|
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
|
|
允許重試此 WebTest 失敗。
|
properties.SyntheticMonitorId
|
string
|
|
此 WebTest 的唯一標識碼。 這通常與 [名稱] 欄位相同。
|
properties.Timeout
|
integer
|
30
|
此 WebTest 的逾時和失敗前的秒數。 預設值為 30。
|
properties.ValidationRules
|
ValidationRules
|
|
驗證規則屬性的集合
|
properties.provisioningState
|
string
|
|
此元件的目前狀態,不論是否已在已定義的資源群組內布建。 使用者無法變更此值,但能夠從中讀取。 值包括 [成功]、[部署]、[已取消] 和 [失敗]。
|
tags
|
object
|
|
資源標籤
|
type
|
string
|
|
Azure 資源類型
|
WebTestGeolocation
要從中執行 WebTest 的地理位置。 您必須指定要執行測試的一或多個位置。
名稱 |
類型 |
Description |
Id
|
string
|
要從中執行之 WebTest 的位置標識碼。
|
WebTestKind
此 Web 測試所監看的 WebTest 種類。 選擇是 Ping、多步驟和標準。
名稱 |
類型 |
Description |
multistep
|
string
|
|
ping
|
string
|
|
standard
|
string
|
|