Unable to trigger a watcher alert when multiple conditions are met

I am trying to implement a logic in watcher to trigger an alert when multiple conditions are met. I have seen a couple of examples where it talks about checking the field ctx.payload.alert.hits.total, but I am sure it is not working as expected as the alerts are still getting triggered when one condition is getting met.

Could someone please look at the below logic and help to improve it or purpose a better way of achieving the desired outcome? I intend to trigger an alert when the CPU is above the value continuously and not just for one blip.
Below is the logic:

"condition": {
"script": {
"source": "ctx.vars.alerting = false; if (ctx.payload.alert.aggregations.avg_cpu_percent.value != null) { ctx.vars.alerting = ctx.payload.alert.aggregations.avg_cpu_percent.value > 0.8 && ctx.payload.alert.hits.total > 10; } return true;",
"lang": "painless"
}
},

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.