Hi
I am trying to send an aggregated hosts keys to webhook actions in parameters fields..
When I use single action and this template
//{{#ctx.payload.hosts}}{{key}} {{/ctx.payload.hosts}}
It perfectly sends an array in the parameter, like below in Hostname,
Watcher Result
"actions": [
{
"id": "my_webhook",
"type": "webhook",
"status": "simulated",
"webhook": {
"request": {
"host": "###############",
"port": ######,
"scheme": "https",
"method": "post",
"path": "/jenkins/job/Testv2/buildWithParameters",
"params": {
"Hostname": "CZ98NWOMAN CZ98PORIAN CZ98DSORAN CZ98DORAN "
},
But when I use iteration in webhook action, it return null in the parameter for all iterations,
If you see below, watcher returning null in the Hostname parameter ""
"actions": [
{
"id": "my_webhook",
"type": "webhook",
"status": "simulated",
"number_of_actions_executed": 6,
"foreach": [
{
"webhook": {
"request": {
"host": "###############",
"port": ###,
"scheme": "https",
"method": "post",
"path": "/jenkins/job/Testv2/buildWithParameters",
"params": {
"Hostname": ""
},
Please help.. How can I parse an array to send a key at a time to each webhook iteration...
Watcher :
{
"trigger": {
"schedule": {
"interval": "5m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"metricbeat-*"
],
"rest_total_hits_as_int": true,
"body": {
"aggs": {
"host": {
"terms": {
"field": "host.hostname",
"order": {
"disk_usage": "desc"
}
},
"aggs": {
"disk_usage": {
"max": {
"field": "system.memory.used.pct"
}
}
}
}
},
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-{{ctx.metadata.window_period}}"
}
}
},
{
"range": {
"system.memory.used.pct": {
"gte": "{{ctx.metadata.threshold}}"
}
}
}
]
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gt": 0
}
}
},
"actions": {
"my_webhook": {
"foreach" : "ctx.payload.hosts",
"max_iterations" : 15,
"webhook": {
"scheme": "https",
"host": "##############",
"port": #####,
"method": "post",
"path": "/jenkins/job/Testv2/buildWithParameters",
"params": {
"Hostname": "{{#ctx.payload.hosts}}{{key}} {{/ctx.payload.hosts}}"
},
"auth": {
"basic": {
"username": "########",
"password": "############"
}
}
}
}
},
"metadata": {
"window_period": "5m",
"threshold": 0.001
},
"transform": {
"script": {
"source": "def threshold_p = ctx.metadata.threshold*100; return [ 'threshold': (int)threshold_p, 'hosts': ctx.payload.aggregations.host.buckets.stream().map(p -> [ 'key': p.key, 'disk_usage': (int) (p.disk_usage.value*100)]).collect(Collectors.toList()) ];",
"lang": "painless"
}
}
}