在微软文档之后,我想查询应用程序Insight资源中的跟踪事件。如果我使用特定的端点直接访问跟踪:
https://api.applicationinsights.io/v1/apps/$aiAppId/events/traces
效果很好。但我无法使用KQL查询:
$aiAppId = 'my_app_insights_app_id'
$aiApiKey = 'my_app_insights_api_key'
$content = (Invoke-WebRequest -Uri "https://api.applicationinsights.io/v1/apps/$aiAppId/query" `
-Method Post -UseBasicParsing `
-Headers @{
'x-api-key' = $aiApiKey
} `
-Body @{
'timespan' = 'PT60M'
'query' = 'traces | where timestamp >= ago(30m)'
}
).Content
$content | ConvertFrom-Json
它产生一个空的结果:
tables
------
{}
从Azure门户执行KQL查询,我得到正确的结果。
我是不是遗漏了什么?任何帮助都很感激。
诚挚的问候。
Giacomo S.
发布于 2021-03-08 00:37:35
$content | ConvertFrom-Json
的类型是PSCustomObject
。因此,正如您所提到的,它显示了结果:
您可以使用像$s = $content | ConvertFrom-Json
这样的代码,然后使用$s.tables.rows
或$s.tables.columns
来显示细节。
或者只需使用$content
,您就可以看到正确的输出:
请考虑编写自己的逻辑来解析结果,而不是直接使用ConvertFrom-Json
。
https://stackoverflow.com/questions/66514384
复制相似问题