加载中

转换

载荷转换处理并更改监控执行上下文中的载荷,以便为监控操作做好准备。Watcher 支持三种类型的载荷转换

注意

载荷转换是可选的。如果未定义任何转换,操作将可以访问由监控输入加载的载荷。

你可以在两个位置定义载荷转换

  • 作为监控定义中的顶层结构。在这种情况下,载荷会在执行任何监控操作之前进行转换。
  • 作为操作定义的一部分。在这种情况下,载荷会在执行该操作之前进行转换。该转换仅应用于该特定操作的载荷。

如果所有操作都需要相同的载荷视图,请在监控定义中定义载荷转换。如果每个操作都需要不同的载荷视图,请在操作定义中定义不同的载荷转换,以便每个操作都有由其专用的载荷转换准备好的载荷。

下面的示例定义了两个载荷转换,一个位于监控级别,另一个位于 my_webhook 操作定义中。

{
  "trigger" : { ...}
  "input" : { ... },
  "condition" : { ... },
  "transform" : {
    "search" : {
      "request": {
        "body" : { "query" : { "match_all" : {} } }
      }
    }
  },
  "actions" : {
    "my_webhook": {
      "transform" : {
      	"script" : "return ctx.payload.hits"
      },
      "webhook" : {
      	"host" : "host.domain",
      	"port" : 8089,
      	"path" : "/notify/{{ctx.watch_id}}"
      }
    }
  ]
}
		
  1. 监控级别的 transform
  2. 操作级别的 transform
© . This website operates independently and is not affiliated with or endorsed by Elasticsearch B.V. All brand names, logos, and trademarks are the property of their respective owners.