4.ElasticSearch预警服务-Watcher详解-Input配置
编程技术  /  houtizong 发布于 3年前   130
Watcher的Input设置用于加载数据到执行Context中,目前支持三种模式设置,分别为simple,search,http。
1.Simple简单输入
可以设定一些静态数据,供Watcher后续阶段进行计算,存储等。
这里可以定义静态数据作为一个字符串(STR),数值(NUM),或一个对象(Object)
{ "input" : { "simple" : { "str" : "tyler", "num" : 29, "obj" : { "str" : "this is a err alert config." } } } ...}
详细案例,可以在input中定义个Name字段,然后在Action中使用ctx.payload.name来调用..
{ "trigger" : { "schedule" : { "daily" : { "at" : "noon" } } }, "input" : { "simple" : { "name" : "John" } }, "actions" : { "reminder_email" : { "email" : { "to" : "[email protected]", "subject" : "Reminder", "body" : "Dear {{ctx.payload.name}}, by the time you read these lines, I'll be gone" } }}
2.Search Input 搜索输入
指定一个搜索条件,这里针对ElasticSearch,并将返回结果加载到Context中。
支持的属性列表:
request.search_type 搜索类型 默认操作 count 可选操作count, dfs_query_and_fetch, dfs_query_then_fetch, query_and_fetch, query_then_fetch, and scan. Elasticsearch 默认为 query_then_fetch.request.indices 搜索索引列表,默认搜索所有request.types 搜索文档类型. 默认搜索所有request.body 搜索请求返回体request.template 搜索模板内容request.indices_options.expand_wildcards 默认open 可选值 all, open, closed, noneequest.indices_options.ignore_unavailable 默认true 是否忽略不可用索引request.indices_options.allow_no_indices 默认true 是否允许使用模糊查询extract 指定返回结果字段数组
Context中提供的属性列表
ctx.watch_id Watch编号ctx.execution_time 执行时间ctx.trigger.triggered_time 触发时间ctx.trigger.scheduled_time 计划触发时间ctx.metadata.* 相关的元数据
案例,搜素Logs索引,类型为event的所有数据
{ "input" : { "search" : { "request" : { "indices" : [ "logs" ], "types" : [ "event" ], "body" : { "query" : { "match_all" : {} } } } } } ...}
使用tempalte搜索
{ "input" : { "search" : { "request" : { "indices" : [ "logs" ], "template" : { "id" : "my_template", "params" : { "value" : 23 } } } } } ...}
带条件的输入
{ "input" : { "search" : { "request" : { "indices" : [ "logs" ], "body" : { "query" : { "match_all" : {} } } } } }, "condition" : { "script" : "return ctx.payload.hits.total > 5" } ...}
3.Http input:HTTP请求输入
允许调用HTTP服务并将返回的Json加载到Context中。
请注意,返回结果必须为Json格式。例如查询ES集群状态,WebService服务等。
支持的属性列表:
request.scheme 默认Http,可选http,httpsrequest.host 必填,host名称request.port 必填 端口request.path 路径request.method HTTP请求方法head, get, post, put,delete.request.headers 请求头 request.params 请求参数 request.auth Http头认证信息request.body HTTP请求体 extract 指定返回结果字段数组
查询其他的ElasticSearch案例:
{ "input" : { "http" : { "request" : { "host" : "example.com", "port" : 9200, "path" : "/idx/_search" } } } ...}
使用完成的ElasticSearch Query DSL案例
{"input" : { "http" : { "request" : { "host" : "host.domain", "port" : 9200, "path" : "/idx/_search", "body" : "\"query\" : { \"match\" : { \"category\" : \"event\"}" } }}
使用Template案例:
{"input" : { "http" : { "request" : { "host" : "host.domain", "port" : 9200, "path" : "/{{ctx.watch_id}}/_search", "body" : "\"query\" : {\"range\": {\"@timestamp\" : {\"from\": \"{{ctx.trigger.triggered_time}}||-5m\",\"to\": \"{{ctx.trigger.triggered_time}}\"}}}" } } }
调用ElasticSearch API 案例
{ "input" : { "http" : { "request" : { "host" : "host.domain", "port" : "9200", "path" : "/_cluster/stats", "params" : { "human" : "true" #优化展示结果 } } } } ...
调用WebService案例:
{ "input" : { "http" : { "request" : { "host" : "host.domain", "port" : "9200", "path" : "/myservice", "auth" : { "basic" : { "username" : "user", "password" : "pass" } } } } } ...}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接