将某些属性发送给天蓝色警报以放松

时间:2019-05-15 14:41:50

标签: azure slack azure-logic-apps

如何从AzureMonitorMetricAlert发送一些属性

完整的JSON如下:

{ 
   "schemaId":"AzureMonitorMetricAlert",
   "data": { 
      "version":"2.0",
      "properties":null,
      "status":"Active",
      "context": { 
         "timestamp":"2019-04-30T14:19:49.4987935Z",
         "id":"/subscriptions/xxxxxxxx/resourceGroups/test/providers/microsoft.insights/metricAlerts/500%20response%20code",
         "name":"500 response code",
         "description":"",
         "conditionType":"DynamicThresholdCriteria",
         "severity":"3",
         "condition": { 
            "windowSize":"PT5M",
            "allOf": [ 
                { 
                  "alertSensitivity":null,
                  "failingPeriods":null,
                  "ignoreDataBefore":null,
                  "metricName":"requests/failed",
                  "metricNamespace":"microsoft.insights/components",
                  "operator":null,
                  "threshold":null,
                  "timeAggregation":"Count",
                  "dimensions": [ 
                      { 
                        "name":"ResourceId",
                        "value":"xxxxxxxxx"
                     },
                      { 
                        "name":"request/resultCode",
                        "value":"500"
                     }
                  ],
                  "metricValue":null
               }
            ]
         },
         "subscriptionId":"xxxxxxxxxxxxxxxx",
         "resourceGroupName":"test",
         "resourceName":"test",
         "resourceType":"microsoft.insights/components",
         "resourceId":"/subscriptions/xxxxxxxxxxx/resourceGroups/test/providers/microsoft.insights/components/tests",
         "portalLink":"https://portal.azure.com/#resource/subscriptions/xxxxxxxx/resourceGroups/dsdsdsdsds"
      }
   }
}

如何将消息发送到松弛消息,包括以下文本:“已发送$ {context.name}的警报。” 我正在尝试:

        "actions": {
            "Post_message": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['slack']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/chat.postMessage",
                    "queries": {
                        "channel": "CHT0EMJ3H",
                        "parse": "full",
                        "text": "tests::::::=>>>>> @{triggerBody()?['context']['name']}"
                    }
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        }

但是它不起作用。如果我仅使用"text": "tests::::::=>>>>> @{triggerBody()}",则会发送完整的JSON,但由于将其解析为字符串,因此很难读取。

1 个答案:

答案 0 :(得分:0)

由于triggerbody()的输出是字符串,因此无法读取属性。因此您可以先将字符串解析为Json,然后读取属性。

因此,您需要使用Parse Json操作,“内容”为@triggerBody(),并且架构单击Use sample payload to generate schema并输入Json。通过此操作,您将能够读取属性。

我使用HTTP请求触发器进行测试并发送邮件,并使用conditionType阅读@{body('Parse_JSON')?['data']?['context']?['conditionType']}

enter image description here

enter image description here