问题描述
在昨天的文章中,介绍了 “【Application Insights】使用CURL命令向Application Insgihts发送测试数据 ”,今天则继续实验通过PowerShell命令来发送测试数据到Application Insights
问题解答
从参考文档中复制出 Powershell脚本,然后只需要修改 Application Insights的Connection String即可。
# Info: Provide either the connection string or ikey for your Application Insights resource
$ConnectionString = ""
$InstrumentationKey = ""
function ParseConnectionString {
param ([string]$ConnectionString)
$Map = @{}
foreach ($Part in $ConnectionString.Split(";")) {
$KeyValue = $Part.Split("=")
$Map.Add($KeyValue[0], $KeyValue[1])
}
return $Map
}
# If ikey is the only parameter supplied, we'll send telemetry to the global ingestion endpoint instead of regional endpoint found in connection strings
If (($InstrumentationKey) -and ("" -eq $ConnectionString)) {
$ConnectionString = "InstrumentationKey=$InstrumentationKey;IngestionEndpoint=https://dc.services.visualstudio.com/"
}
$map = ParseConnectionString($ConnectionString)
$url = $map["IngestionEndpoint"] + "v2/track"
$ikey = $map["InstrumentationKey"]
$lmUrl = $map["LiveEndpoint"]
$time = (Get-Date).ToUniversalTime().ToString("o")
$availabilityData = @"
{
"data": {
"baseData": {
"ver": 2,
"id": "SampleRunId",
"name": "Microsoft Support Sample Webtest Result",
"duration": "00.00:00:10",
"success": true,
"runLocation": "Region Name",
"message": "Sample Webtest Result",
"properties": {
"Sample Property": "Sample Value"
}
},
"baseType": "AvailabilityData"
},
"ver": 1,
"name": "Microsoft.ApplicationInsights.Metric",
"time": "$time",
"sampleRate": 100,
"iKey": "$ikey",
"flags": 0
}
"@
# Uncomment one or more of the following lines to test client TLS/SSL protocols other than the machine default option
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::SSL3
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::TLS
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::TLS11
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::TLS12
# [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::TLS13
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri $url -Method POST -Body $availabilityData -UseBasicParsing
执行效果图:
参考资料
用于发送可用性测试结果的 PowerShell 脚本:https://learn.microsoft.com/zh-cn/troubleshoot/azure/azure-monitor/app-insights/investigate-missing-telemetry#powershell-script-send-availability-test-result
使用curl命令向Application Insights发送测试数据:https://www.cnblogs.com/lulight/p/17953251
【end】
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
标签:ConnectionString,System,Application,Net,Powershell,SecurityProtocolType,Insights From: https://blog.51cto.com/u_13773780/9165767