6.ElasticSearch预警服务-Watcher详解-Transform设置
编程技术  /  houtizong 发布于 3年前   100
ElasticSearch预警服务-Watcher详解-Transform设置
Transform(数据转换),在Watcher服务的Action执行前执行。
可以执行Transform的位置有两次,分别是:
1.全局定义(Watch Level),将对所有的Watch动作生效
2.局部定义(Action Level),只对指定的Watch动作生效
设置案例:
{ "trigger" : { ...} "input" : { ... }, "condition" : { ... }, "transform" : { #此处为全局的 "search" : { "body" : { "query" : { "match_all" : {} } } } } "actions" : { "tyler_webhook": { "transform" : { #次数为局部 "script" : "return ctx.payload.hits" } "webhook" : { "host" : "host.domain", "port" : 8089, "path" : "/notify/{{ctx.watch_id}}" } } ] ...}
目前支持的三种定义类型为search, script ,chain
1.Search Transform
执行一个查询,并将返回结果替换Context中的内容。
来看一下局部定义的Search Transform:
{ ... "transform" : { "search" : { "body" : { "query" : { "match_all" : {} } } } } ...}
#带参数定义
{ "transform" : { "search" : { "search_type" : "count", #执行Count操作 "indices" : [ "logstash-*" ], #查询所有以logstash开头的索引 "body" : { "query" : { "match" : { "priority" : "error"} #查询proiority为Error的数据 } } } }}
#支持ES的全部搜索API格式...
{ "transform" : { "search" : { "search_type" : "count", "index" : [ "logstash-*" ], "type" : "event", "body" : { "query" : { "filtered" : { "filter" : { "bool" : { "must" : [ { "range" : { "@timestamp" : { "from" : "{{ctx.trigger.scheduled_time}}||-30s", "to" : "{{ctx.trigger.triggered_time}}" } } }, { "query" : { "match" : { "priority" : "error"} } } ] } } } } } } }}
#支持 inline template查询
{ "transform" : { "search" : { "search_type" : "count", "index" : [ "logstash-*" ], "type" : "event", "body" : { "template" { "inline" : { "query" : { "filtered" : { "filter" : { "bool" : { "must" : [ { "range" : { "@timestamp" : { "from" : "{{ctx.trigger.scheduled_time}}||-30s", "to" : "{{ctx.trigger.triggered_time}}" } } }, { "query" : { "match" : { "priority" : "{{priority}}"} } } ] } } } }, "params" : { "priority" : "error" } } } } } }}
2.Script Transform
需要注意的是,从ESv1.4.3开始, inline groovy scripts功能是默认关闭的,请注意开启
简单的脚本设置定义:
{ ... "transform" : { "script" : "return [ time : ctx.trigger.scheduled_time ]" #Groovy脚本 } ...}
3.Chain Transform
链式数据转换,指可以指定多个Transform组成数据量,一个Transform的输出作为下一个Transfrom的输入.
{ ... "transform" : { "chain" : [ #定义格式 { "search" : { #搜索Transform,执行count查询 "search_type" : "count", "indices" : [ "logstash-*" ], "body" : { "query" : { "match" : { "priority" : "error"} } } } }, { #脚本Transform,将count结果赋值给Error_count字段 "script" : "return [ error_count : ctx.payload.hits.total ]" } ] } ...}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接