5.ElasticSearch预警服务-Watcher详解-Condition设置

编程技术  /  houtizong 发布于 3年前   183

ElasticSearch预警服务-Watcher详解-Condition设置


Condition用于在Watcher触发后决定是否去执行Action动作.
目前支持的类型有4种,分别是always,never,script,compare.
如果没有进行设置,则默认为always类型。
当Condition执行时,可以访问Context中的数据,即Script和Compare可以使用其中的数据来决定是否满足条件。

1.Always Condition
设置为Always后,Action动作总会执行除非遇到throttled(节流)的情况.

PUT _watcher/watch/my-watch{  ...  "condition" : {    "always" : {}  }  ...}

 
2.Never Condition
设置为Never后,Action动作永远不会执行.

PUT _watcher/watch/my-watch{  ...  "condition" : {    "never" : {}  }  ...}

 
3.Script Condition
默认脚本语言是Groovy。这里可以设置ElasticSearch支持的所有编程语言。

{  ...  "condition" : {    "script" : "return true" #默认Groovy  }  ...}

 
3.1.InLineScript

{  ...  "condition" : {    "script" : {      "inline" : "return true";    }  }  ...}

 带参数的设置

{  ...  "condition" : {    "script" : {      "inline" : "return result";      "lang" : "groovy",      "params" : {        "result" : true   #参数设置      }    }  }  ...}

 
3.2.File Script 使用脚本文件,脚本文件必须放置到config/scripts目录下

{  ...  "condition" : {    "script" : {      "file" : "my_script";    }  }  ...}使用脚本文件并带参数设置{  ...  "condition" : {    "script" : {      "file" : "my_script";      "lang" : "groovy",      "params" : {        "result" : true      }    }  }  ...}

 
3.3.Indexed  Scripts

{  ...  "condition" : {    "script" : {      "id" : "my_script"    }  }  ...}使用索引脚本并带参数设置{  ...  "condition" : {    "script" : {      "id" : "my_script",      "lang" : "javascript",      "params" : {"color": "red"}    }  }  ...}

 
3.4使用Script获取Context中的数据

{  "input" : {    "search" : {      "search_type" : "count",      "indices" : "log-events",      "body" : {        "query" : { "match" : { "status" : "error" } }      }    }  },  "condition" : {    "script" : {#获取命中数,并判断大于节流阀值      "script" : "return ctx.payload.hits.total > threshold",      "params" : {        "threshold" : 5      }    }  }  ...}

 
4.Compare Condition

通过与Watcher Context中的模型数据进行比较,即可以使用eq,not_eq,gt,gte,lt,lte等判断条件。

{  ...  "condition" : {    "compare" : {      "ctx.payload.hits.total" : {        "gte" : 5      }  }  ...}

对于日期格式的数据,可以使用表达式。

{  ...  "condition" : {    "compare" : {      "ctx.execution_time" : {        "gte" : "<{now-5m}>"      }  }  ...}

 #Context中数据进行比较

{  ...  "condition" : {    "compare" : {      "ctx.payload.aggregations.status.buckets.error.doc_count" : {        "not_eq" : "{{ctx.payload.aggregations.handled.buckets.true.doc_count}}"      }  }  ...}

 

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客