我使用 Application Insight 工作簿。 我向工作簿添加查询以使用 app 函数选择一些数据。
我有带有 JSON 输入的下拉列表
[
{
"label": "Test",
"value": {
"m":"<subscription-test-m>/<resource group-m>/<instance-m>",
"e":"<subscription-test-e>/<resource group-e>/<instance-e>"
}
},
{
"label": "Prod",
"value": {
"m":"<subscription-prod-m>/<resource group-m>/<instance-m>",
"e":"<subscription-prod-e>/<resource group-e>/<instance-e>"
},
"selected":true
}
]
我正在尝试为应用程序功能提供动态环境标识符,例如:
app("{Envionment:value.m}").requests;
我明白了
The request had some invalid properties: "Identity '[object Object]' could not be resolved"
有人知道如何提取和提供 json 子值作为此 app 函数的字面值吗?
如果您将“对象”填充到值字段中,您应该能够使用参数的
JSONPath
语法来获取值的一部分:
但是:
您需要将查询选项与 JSON 数据源一起使用,它比期望值是字符串而不是对象的“从:JSON 获取数据”选项更强大。 JSON 数据源还允许替换 json 内容中的参数,就像其他查询数据源一样。
您需要重新排序 json 中的字段,以便值在前,标签在后。数据源按照它在对象中看到的顺序创建列,下拉列表期望第一列是值,第二列是标签。
然后在格式化参数时使用 jsonpath 语法
{parameterName:$.fieldName}
参数通常允许特殊类型的格式化,如果您使用 :
并且之后的特定内容仍在大括号内。具体参见 https://learn.microsoft.com/en-us/azure/azure-monitor/visualize/workbooks-parameters#format-parameters-by-using-jsonpath jsonpath
完整的工作示例:
{
"version": "Notebook/1.0",
"items": [
{
"type": 9,
"content": {
"version": "KqlParameterItem/1.0",
"parameters": [
{
"id": "d48de334-4741-4deb-b0fd-4f0f2df2acf6",
"version": "KqlParameterItem/1.0",
"name": "paramWithObject",
"type": 2,
"query": "{\"version\":\"1.0.0\",\"content\":\"[\\r\\n { \\r\\n \\\"value\\\": {\\r\\n \\\"m\\\":\\\"<subscription-test-m>/<resource group-m>/<instance-m>\\\",\\r\\n \\\"e\\\":\\\"<subscription-test-e>/<resource group-e>/<instance-e>\\\"\\r\\n },\\r\\n \\\"label\\\": \\\"Test\\\"\\r\\n }, \\r\\n { \\r\\n \\\"value\\\": {\\r\\n \\\"m\\\":\\\"<subscription-prod-m>/<resource group-m>/<instance-m>\\\",\\r\\n \\\"e\\\":\\\"<subscription-prod-e>/<resource group-e>/<instance-e>\\\"\\r\\n },\\r\\n \\\"label\\\": \\\"Prod\\\",\\r\\n \\\"selected\\\":true\\r\\n }\\r\\n]\",\"transformers\":null}",
"typeSettings": {
"additionalResourceOptions": [],
"showDefault": false
},
"timeContext": {
"durationMs": 86400000
},
"queryType": 8
}
],
"style": "above",
"queryType": 8
},
"name": "parameters - 0"
},
{
"type": 1,
"content": {
"json": "value of `paramWithObject`:\r\n```\r\n{paramWithObject}\r\n```\r\n\r\nvalue of `e`: `{paramWithObject:$.e}`\r\n\r\n\r\nvalue of `m`: `{paramWithObject:$.m}`\r\n\r\n"
},
"name": "text - 1"
}
],
"$schema": "https://github.com/Microsoft/Application-Insights-Workbooks/blob/master/schema/workbook.json"
}