json - Elasticsearch 观察器和 Microsoft Teams webhook

标签 json elasticsearch webhooks microsoft-teams elasticsearch-watcher

我已经拼命尝试了 5 天来创建一个 elasticsearch 观察者警报,该警报会在传入的 webhook 团队上发送通知。但是,我收到的答案是“通用传入 webhook 收到错误的有效负载”。我不明白为什么它不起作用。

{
  "trigger": {
    "schedule": {
      "interval": "2m"
    }
  },
  "input": {
    "simple": {
      "summary": "Test Nom",
      "text": "test"
    }
  },
  "condition": {
    "always": {}
  },
  "actions": {
    "MS_TEAMS_PORT443": {
      "webhook": {
        "scheme": "https",
        "host": "outlook.office.com",
        "port": 443,
        "method": "post",
        "path": "/webhook/XYZ",
        "params": {},
        "headers": {
          "content-type": "application/json"
        },
        "body": "{{#toJson}}ctx.payload.summary{{/toJson}}"
      }
    }
  }
}

这是我启动它时的响应:

{
  "watch_id": "_inlined_",
  "node": "QUApyNq4S5GyhHF-CuNjfg",
  "state": "executed",
  "status": {
    "state": {
      "active": true,
      "timestamp": "2019-10-21T08:40:39.802Z"
    },
    "last_checked": "2019-10-21T08:40:39.802Z",
    "last_met_condition": "2019-10-21T08:40:39.802Z",
    "actions": {
      "MS_TEAMS_PORT443": {
        "ack": {
          "timestamp": "2019-10-21T08:40:39.802Z",
          "state": "awaits_successful_execution"
        },
        "last_execution": {
          "timestamp": "2019-10-21T08:40:39.802Z",
          "successful": false,
          "reason": "received [400] status code"
        }
      }
    },
    "execution_state": "executed",
    "version": -1
  },
  "trigger_event": {
    "type": "manual",
    "triggered_time": "2019-10-21T08:40:39.802Z",
    "manual": {
      "schedule": {
        "scheduled_time": "2019-10-21T08:40:39.802Z"
      }
    }
  },
  "input": {
    "simple": {
      "summary": "Test Nom",
      "text": "test"
    }
  },
  "condition": {
    "always": {}
  },
  "metadata": {
    "name": "testJsonALaMano",
    "xpack": {
      "type": "json"
    }
  },
  "result": {
    "execution_time": "2019-10-21T08:40:39.802Z",
    "execution_duration": 125,
    "input": {
      "type": "simple",
      "status": "success",
      "payload": {
        "summary": "Test Nom",
        "text": "test"
      }
    },
    "condition": {
      "type": "always",
      "status": "success",
      "met": true
    },
    "actions": [
      {
        "id": "MS_TEAMS_PORT443",
        "type": "webhook",
        "status": "failure",
        "reason": "received [400] status code",
        "webhook": {
          "request": {
            "host": "outlook.office.com",
            "port": 443,
            "scheme": "https",
            "method": "post",
            "path": "/webhook/XYZ",
            "headers": {
              "content-type": "application/json"
            },
            "body": "Test Nom"
          },
          "response": {
            "status": 400,
            "headers": {
              "date": [
                "Mon, 21 Oct 2019 08:40:38 GMT"
              ],
              "content-length": [
                "49"
              ],
              "expires": [
                "-1"
              ],
              "x-beserver": [
                "VI1PR07MB5053"
              ],
              "x-aspnet-version": [
                "4.0.30319"
              ],
              "x-proxy-backendserverstatus": [
                "400"
              ],
              "x-cafeserver": [
                "VE1PR03CA0023.EURPRD03.PROD.OUTLOOK.COM"
              ],
              "x-calculatedbetarget": [
                "VI1PR07MB5053.eurprd07.prod.outlook.com"
              ],
              "request-id": [
                "6d651f70-74b5-4010-a2a6-662666fa9985"
              ],
              "pragma": [
                "no-cache"
              ],
              "x-msedge-ref": [
                "Ref A: C6E8A3DCFF9541DD95D63FD71ACD695C Ref B: PAR02EDGE0513 Ref C: 2019-10-21T08:40:39Z"
              ],
              "x-feserver": [
                "VE1PR03CA0023"
              ],
              "x-powered-by": [
                "ASP.NET"
              ],
              "x-backendhttpstatus": [
                "400"
              ],
              "content-type": [
                "text/plain; charset=utf-8"
              ],
              "cache-control": [
                "no-cache"
              ]
            },
            "body": "Bad payload received by generic incoming webhook."
          }
        }
      }
    ]
  },
  "messages": []
}

最佳答案

错误的 body 陈述。需要在正文中发送文本。把 body 改成这样

"body": "{\"text\": \"{{ctx.payload.summary}}\"}"

关于json - Elasticsearch 观察器和 Microsoft Teams webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58482704/

相关文章:

node.js - 如果我的服务器无法接收 Webhook 请求,Stripe API 会重试吗?

node.js - 调查猴子 Webhook

json - 带有 Spring Boot REST Controller 和 JSON 的空字段

java - 使用Elasticsearch在Grails中处理类的意外问题字节

elasticsearch - 用!索引以他们的名义不能被过滤以恢复

c# - 有没有一种简单的方法可以在 Windows 窗体中接收 Webhooks、推送通知或 SMS?

javascript - Ember.js RESTAdapter : Access JSON params when setting headers

JSON Jackson 共享引用

iOS 表格 View 自动换行重叠

elasticsearch - 如何使用 spring 数据 elasticSearch 映射连接类型