Hi All,
I am executing a watcher which post data to an API. In it self this works fine, however the data format is something I am struggling with. My watcher looks like this.
{
"trigger": {
"schedule": {
"cron": "0 */15 * * * ?"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"clog-*"
],
"types": [],
"body": {
"_source": [
"login",
"ip",
"block_data",
"block_reason",
"from",
"dw002"
],
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "source_affiliate:nlmail AND dw002:true",
"analyze_wildcard": true,
"default_field": "*"
}
},
{
"range": {
"@timestamp": {
"gte": "now-15m",
"lte": "now"
}
}
}
],
"filter": [],
"should": [],
"must_not": []
}
}
}
}
}
},
"condition": {
"script": {
"source": "boolean trigger=false;ArrayList offenders = new ArrayList();for(int i=0;i<ctx.payload.hits.hits.size();i++){offenders.add(i, ctx.payload.hits.hits[i]._source);}ctx.vars.offenders=offenders;trigger=true;return trigger;",
"lang": "painless",
"params": {
"dw002": 1
}
}
},
"actions": {
"xredir_post": {
"webhook": {
"scheme": "http",
"host": "10.80.3.109",
"port": 80,
"method": "post",
"path": "/v1/block_dw002",
"params": {},
"headers": {
"Content-Type": "application/json"
},
"auth": {
"basic": {
"username": "admin",
"password": "::es_redacted::"
}
},
"body": "{{ctx.vars.offenders}}"
}
}
}
}
The data it posts looks like this.
"{0={dw002=true, ip=41.65.69.99, block_reason=botnetloginfrom, from=dddd@blabla.nl, block_data=41.65.69.99 list=smtp-known-botnetip.black.dnsbl.blabla.local, login=dddd@blabla.nl}, 1={ip=11.114.156.159, dw002=true, block_reason=botnetloginfrom, from=kees.ddd@blabla.nl, block_data=41.114.156.159 list=smtp-known-botnetip.black.dnsbl.blabla.local, login=kees.ddd@blabla.nl}, 2={ip=191.2.132.77, dw002=true, block_reason=botnetloginfrom, from=dddd@xxxxxx.nl, block_data=190.2.132.77 list=sip24.xxxxxx.com, login=dddd@xxxxxx.nl}, 3={ip=45.76.125.140, dw002=true, block_reason=botnetloginfrom, from=j.dddd@ddddd.nl, block_data=45.76.125.140 list=smtp-known-botnetip.black.dnsbl.blabla.local, login=j.selenthijssen@dddd.nl}, 4={dw002=true, ip=5.147.49.92, block_reason=botnetloginfrom, from=fam.ffff@blabla.nl, block_data=5.147.49.92 list=sip24.xxxxxx.com, login=fam.sssn@blabla.nl}, 5={ip=17.139.24.142, dw002=true, block_reason=botnetloginfrom, from=keesennicole@xxxxxx.nl, block_data=17.139.24.142 list=sip.xxxxxx.com, login=keeddddnicole@xxxxxx.nl}, 6={ip=45.16.125.140, dw002=true, block_reason=botnetloginfrom, from=w.ddddd@blabla.nl, block_data=45.76.125.140 list=smtp-known-botnetip.black.dnsbl.blabla.local, login=w.s11en@blabla.nl}, 7={dw002=true, ip=109.201.133.236, block_reason=botnetloginfrom, from=chwk@xxxxxx.nl, block_data=109.201.133.236 list=sip24.xxxxxx.com, login=chwk@h111e.nl}}"
I basically need to send a array with the _source to the API but I seem to do something wrong..
I hope somebody can give me some advice.
Paul.