Azure 是否可以按计划任务/频率通过powershell更新application insights中的URL Is可用性测试
我在azure中有许多环境,它们为我们的一位客户使用本地Restful服务。目前,我们在资源组中配置了应用程序洞察,并配置了可用性测试以按指定频率ping URL,配置了洞察警报(停机时发送电子邮件) 访问令牌嵌入到需要频繁更新的URL中。是否可以通过编程方式更新突出显示的URL以替换令牌(计划/自动) 只是想知道可以使用哪些技术定期(每两周)更新可用性URL Azure功能? 是否将某种PowerShell脚本作为计划任务? 使用此处示例的ARM模板Azure 是否可以按计划任务/频率通过powershell更新application insights中的URL Is可用性测试,azure,powershell,azure-application-insights,Azure,Powershell,Azure Application Insights,我在azure中有许多环境,它们为我们的一位客户使用本地Restful服务。目前,我们在资源组中配置了应用程序洞察,并配置了可用性测试以按指定频率ping URL,配置了洞察警报(停机时发送电子邮件) 访问令牌嵌入到需要频繁更新的URL中。是否可以通过编程方式更新突出显示的URL以替换令牌(计划/自动) 只是想知道可以使用哪些技术定期(每两周)更新可用性URL Azure功能? 是否将某种PowerShell脚本作为计划任务? 使用此处示例的ARM模板 如果您能就如何有效地执行此任务并使用最合
如果您能就如何有效地执行此任务并使用最合适的技术提供任何建议,我们将不胜感激。我必须说,似乎没有提供PowerShell模块来修改App Insight webtest的url,但我们可以通过REST API来完成。请尝试下面的PowerShell:
$clientId = "<your Azure AD application ID>"
$clientSec="<your Azure AD application secret>"
$appInsightName ="<your app insight name>"
$webtestName="<your webtest name>"
$subscriptionId = "<your subscription ID>"
$resourceGroupName = "<your resource group name that your app insight in>"
$tenant = "<your tenant name/ID>"
$newUrl = "<the new URL>"
#get access token to fetch details of webtest
$body=@{
"grant_type"="client_credentials";
"resource"="https://management.azure.com/";
"client_id"= $clientId;
"client_secret" = $clientSec
}
$accessToken=(Invoke-RestMethod -Uri "https://login.windows.net/$tenant/oauth2/token" -Method POST -Body $body ).access_token
$uri = "https://management.azure.com/subscriptions/{0}/resourcegroups/{1}/providers/microsoft.insights/webtests/{2}-{3}?api-version=2015-05-01"
$uri = $uri.Replace("{0}",$subscriptionId).Replace("{1}",$resourceGroupName).Replace("{2}",$webtestName).Replace("{3}",$appInsightName)
$webtestResult = Invoke-RestMethod -Uri $uri -Method GET -Headers @{"Authorization"="Bearer $accessToken"}
#modify the url of webtest
$webTestConf = [xml]@($webtestResult.properties.Configuration.WebTest)
$webTestConf.WebTest.Items.Request.Url = $newUrl
#structure request json to update webtest
$locations = $webtestResult.properties.Locations | ConvertTo-Json
$Configuration = $webTestConf.WebTest.OuterXml | ConvertTo-Json
$Configuration = $Configuration.Replace("\u003c","<").replace("\u003e",">")
$location = $webtestResult.location
$tags = $webtestResult.tags| ConvertTo-Json
$name = $webtestResult.properties.Name
$kind = $webtestResult.properties.Kind
$json = @"
{
"location":"$location",
"tags":$tags,
"properties":{
"Name":"$name",
"Enabled": true,
"Frequency": 300,
"Timeout": 120,
"Locations":$locations,
"Configuration":{"webtest":$Configuration},
"Kind":"$kind"
}
}
"@
Invoke-RestMethod -Uri $uri -Method PUT -Body $json -Headers @{"Authorization"="Bearer $accessToken";"Content-Type"="application/json"}
$clientId=“”
$clientSec=“”
$appInsightName=“”
$webtestName=“”
$subscriptionId=“”
$resourceGroupName=“”
$tenant=“”
$newUrl=“”
#获取访问令牌以获取webtest的详细信息
$body=@{
“授权类型”=“客户端凭据”;
“资源”=”https://management.azure.com/";
“客户id”=$clientId;
“客户机密”=$clientSec
}
$accessToken=(调用RestMethod-Uri)https://login.windows.net/$tenant/oauth2/token“-Method POST-Body$Body).访问令牌
$uri=”https://management.azure.com/subscriptions/{0}/resourcegroups/{1}/providers/microsoft.insights/webtests/{2}-{3}?api版本=2015-05-01“
$uri=$uri.Replace(“{0}”,$subscriptionId)。Replace(“{1}”,$resourceGroupName)。Replace(“{2},$webtestName)。Replace(“{3}”,$appInsightName)
$webtestResult=Invoke RestMethod-Uri$Uri-Method GET-Headers@{“Authorization”=“Bearer$accessToken”}
#修改webtest的url
$webTestConf=[xml]@($webtestResult.properties.Configuration.WebTest)
$webTestConf.WebTest.Items.Request.Url=$newUrl
#结构请求json以更新webtest
$locations=$webtestResult.properties.locations |转换为Json
$Configuration=$webTestConf.WebTest.OuterXml |转换为Json
$Configuration=$Configuration.Replace(“\u003c”,”)
$location=$webtestResult.location
$tags=$webtestResult.tags |转换为Json
$name=$webtestResult.properties.name
$kind=$webtestResult.properties.kind
$json=@”
{
“位置”:“$location”,
“标签”:$tags,
“财产”:{
“名称”:“$Name”,
“启用”:正确,
“频率”:300,
“超时”:120,
“地点”:$地点,
“配置”:{“webtest”:$Configuration},
“种类”:“$Kind”
}
}
"@
调用RestMethod-Uri$Uri-Method PUT-Body$json-Headers@{“Authorization”=“Bearer$accessToken”;“Content Type”=“application/json”}
除了Azure功能外,您还可以使用来满足您的需求
顺便说一句,此powershell演示使用服务原则连接到您的Azure订阅,确保您的Azure ad应用程序有权修改您的app insight。如果您有任何不清楚的地方,请随时告诉我。这个问题不能通过 您好@DamoB,您是否已成功更新您的应用程序洞察可用性测试URL?