设为首页 收藏本站
查看: 1556|回复: 0

[经验分享] 4.ElasticSearch预警服务-Watcher详解-Input配置

[复制链接]

尚未签到

发表于 2017-5-21 09:15:14 | 显示全部楼层 |阅读模式
  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" : "to@host.domain",
"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, none
equest.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,https
request.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"
}
}
}
}
}
...
}








     
     
     
     

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-379489-1-1.html 上篇帖子: Elasticsearch模块功能之-索引分片分配(Index shard allocation) 下篇帖子: Elasticsearch mongodb river同步大量数据内存溢出
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表