Hello,
Is there a way to create a new payload in the condition portion of watcher?
I have this watcher that evaluates buckets, it checks to see if the buckets pass a condition. The issue I want to filter out the buckets in the conditon and currently its passing all the buckets as the condition evaluates true which is not what I want.
"condition": {
"script": {
"source": """
def result = false;
def filteredBuckets = [];
for (bucket in ctx.payload.aggregations.by_host_and_object.buckets) {
def mostRecentEvent = bucket.most_recent_event.hits.hits[0]._source.event.outcome;
def failuresCount = bucket.failures.doc_count;
if (mostRecentEvent == 'failure' && failuresCount > 1) {
filteredBuckets.add(bucket);
return true;
}
},
ctx.payload.filtered_buckets = filteredBuckets;
return false;
""",
"lang": "painless"
}
}
As you can see I attempted to assign the filteredBuckets to ctx.payload.filtered_buckets.
I might be approaching this wrong