Merge pull request #2371 from microsoft/micmax/refactor-post-telemetry-script
Refactor PostTelemetry.ps1 script
This commit is contained in:
Коммит
a04d0e4b39
|
@ -1,13 +1,40 @@
|
|||
$url="https://{IngestionEndpoint-from-Component-ConnectionString}/v2/track"
|
||||
$iKey="{test-iKey}"
|
||||
Write-Host $url, $iKey
|
||||
param (
|
||||
[string]$ConnectionString,
|
||||
[string]$InstrumentationKey
|
||||
)
|
||||
|
||||
$time = Get-Date
|
||||
$time = $time.ToUniversalTime().ToString('o')
|
||||
function ParseConnectionString {
|
||||
param (
|
||||
[string]$ConnectionString
|
||||
)
|
||||
|
||||
$availabilityData = @"
|
||||
$Map = @{}
|
||||
|
||||
foreach ($Part in $ConnectionString.Split(";")) {
|
||||
$KeyValue = $Part.Split("=")
|
||||
$Map.Add($KeyValue[0], $KeyValue[1])
|
||||
}
|
||||
|
||||
return $Map
|
||||
}
|
||||
|
||||
# Exit with error if either both or neither of these parameters are provided
|
||||
if (("" -eq $ConnectionString) -eq ("" -eq $InstrumentationKey)) {
|
||||
Write-Error "Please provide one of the parameters: 'ConnectionString' or 'InstrumentationKey'" -ErrorAction Stop
|
||||
}
|
||||
|
||||
# Build the connection string using the instrumentation key
|
||||
If ($InstrumentationKey) {
|
||||
$ConnectionString = "InstrumentationKey=$InstrumentationKey;IngestionEndpoint=https://dc.services.visualstudio.com/"
|
||||
}
|
||||
|
||||
$Map = ParseConnectionString($ConnectionString)
|
||||
$Url = $Map["IngestionEndpoint"] + "v2/track"
|
||||
$IKey = $Map["InstrumentationKey"]
|
||||
$Time = (Get-Date).ToUniversalTime().ToString("o")
|
||||
$AvailabilityData = @"
|
||||
{
|
||||
"data": {
|
||||
"data": {
|
||||
"baseData": {
|
||||
"ver": 2,
|
||||
"id": "TestId",
|
||||
|
@ -22,14 +49,15 @@ $availabilityData = @"
|
|||
},
|
||||
"baseType": "AvailabilityData"
|
||||
},
|
||||
"ver": 1,
|
||||
"ver": 1,
|
||||
"name": "Microsoft.ApplicationInsights.Metric",
|
||||
"time": "$time",
|
||||
"time": "$Time",
|
||||
"sampleRate": 100,
|
||||
"iKey": "$iKey",
|
||||
"iKey": "$IKey",
|
||||
"flags": 0
|
||||
}
|
||||
"@
|
||||
|
||||
Invoke-WebRequest -Uri $url -Method POST -Body $availabilityData -Verbose -Debug -UseBasicParsing
|
||||
Write-Host "URL: $Url, IKey: $IKey"
|
||||
# Expected Output: {"itemsReceived":1,"itemsAccepted":1,"errors":[]}
|
||||
Invoke-WebRequest -Uri $Url -Method POST -Body $AvailabilityData -Verbose -Debug -UseBasicParsing
|
||||
|
|
Загрузка…
Ссылка в новой задаче