从Slack生成的JSON中获取一些属性 [英] Get some properties from JSON produced by Slack
问题描述
我有一个JOSN档案女巫是由 AzureMonitorMetricAlert被发送到松弛。
$
```
{
" schemaId" : < span id ="x_x_x_x_x_x_s-4"style ="color:#555555; font-family:'Ubuntu Mono',Menlo,Monaco,Co nsolas,'Courier New',monospace; font-size:16px">" 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 ,
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度ID ="x_x_x_x_x_x_s-71"style ="font-weight:700;颜色:#333333; font-family:'Ubuntu Mono',Menlo,Monaco,Consolas,'Courier New',等宽; font-size:16px">" metricName" : " requests / failed" ,
" metricNamespace" : " microsoft.insights / components" ,
" operator" : null ,
" threshold" : null ,
" timeAggregation" : " Count" ,
" dimensions" : [
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; " name" : " ResourceId" ,
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; " value" : " xxxxxxxxx"
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; } ,
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; " name" : " request / resultCode" ,
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; " value" : " 500"
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; }
] ,
" metricValue" : null
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度ID =" x_x_x_x_x_x_s-118\"风格="COLOR:#666666; font-family:'Ubuntu Mono',Menlo,Monaco,Consolas,'Courier New',等宽; font-size:16px">}
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度ID =" x_x_x_x_x_x_s-119\" 样式="颜色:# 666666; font-family:'Ubuntu Mono',Menlo,Monaco,Consolas,'Courier New',等宽; font-size:16px">]
} ,
" 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"
}
}
}
```
How can I sent to slack message: "Alert with name ${data.context.name} was triggered for ${data.resourceName}?
I was trying sth like:
```
I have a JOSN file witch is produced by AzureMonitorMetricAlert is sent to slack.
```
{
"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"
}
}
}
```
How can I sent to slack message: "Alert with name ${data.context.name} was triggered for ${data.resourceName}?
I was trying sth like:
```
推荐答案
Hi I tried your scenario with sending the input as trigger body in the logic app. please find the details below on how i did it:
Hi I tried your scenario with sending the input as trigger body in the logic app. please find the details below on how i did it:
"definition": {
"
schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Post_message": {
"inputs": {
"host": {
"connection": {
"name": "@parameters(’
schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Post_message": { "inputs": { "host": { "connection": { "name": "@parameters('
connections’)[’slack’][’connectionId’]"
}
},
"method": "post",
"path": "/chat.postMessage",
"queries": {
"channel": "CJT3C27K8",
"text": "\"Alert with name @{triggerBody()?[’data’]?[’context’][’name’]} was triggered for @{triggerBody()?[’data’]?[’context’][’resourceName’]}"
}
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"
connections')['slack']['connectionId']" } }, "method": "post", "path": "/chat.postMessage", "queries": { "channel": "CJT3C27K8", "text": "\"Alert with name @{triggerBody()?['data']?['context']['name']} was triggered for @{triggerBody()?['data']?['context']['resourceName']}" } }, "runAfter": {}, "type": "ApiConnection" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": { "
这篇关于从Slack生成的JSON中获取一些属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!