|
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"
}
}
}
}
}
...
}
|
|