我正在尝试访问 Azure Logic APPS Json 主体中的隐藏值。我有来自 HTTP 响应的 json 正文,我想访问隐藏的值,我不知道如何访问它。
一般来说,我们将使用以下代码访问Python中的隐藏值:
body.data.alertContext.condition.allOf.dimentions[0].value
演示 JSON
”Headers”:{},
“body”{
"schemaId": "azureMonitorCommonAlertSchema",
"data": {
"essentials": {
"alertId": "/subscriptions/<subscription ID>/providers/Microsoft.AlertsManagement/alerts/b9569717-bc32-442f-add5-83a997729330",
"alertRule": "WCUS-R2-Gen2",
"severity": "Sev3",
"signalType": "Metric",
"monitorCondition": "Resolved",
"monitoringService": "Platform",
"alertTargetIDs": [
"/subscriptions/<subscription ID>/resourcegroups/pipelinealertrg/providers/microsoft.compute/virtualmachines/wcus-r2-gen2"
],
"configurationItems": [
"wcus-r2-gen2"
],
"originAlertId": "3f2d4487-b0fc-4125-8bd5-7ad17384221e_PipeLineAlertRG_microsoft.insights_metricAlerts_WCUS-R2-Gen2_-117781227",
"firedDateTime": "2019-03-22T13:58:24.3713213Z",
"resolvedDateTime": "2019-03-22T14:03:16.2246313Z",
"description": "",
"essentialsVersion": "1.0",
"alertContextVersion": "1.0"
},
"alertContext": {
"properties": null,
"conditionType": "SingleResourceMultipleMetricCriteria",
"condition": {
"windowSize": "PT5M",
"allOf": [
{
"metricName": "Percentage CPU",
"metricNamespace": "Microsoft.Compute/virtualMachines",
"operator": "GreaterThan",
"threshold": "25",
"timeAggregation": "Average",
"dimensions": [
{
"name": "ResourceId",
"value": "3efad9dc-3d50-4eac-9c87-8b3fd6f97e4e"
}
],
"metricValue": 7.727
}
]
}
},
"customProperties": {
"Key1": "Value1",
"Key2": "Value2"
}
}
}
由于专业原因,我无法分享 json 响应。我如何编写表达式来访问此字符串值并将其设置为 azure 逻辑应用程序中的变量
我的答案的开头取决于您想要从中提取数据的操作类型,但我将假设它是来自 HTTP 操作的响应。
您需要使用方括号和单引号来表示您想要的内容。您需要使用这样的语法...
body('HTTP')['data']['alertContext']['condition']['allOf']['dimensions'][0]['value']
...或者您可以使用
Parse JSON
,但如果 JSON 的结构可能不同,那么您需要调整您的架构,以便它能够满足它。
此链接有帮助...