# Unable to trigger a watcher alert when multiple conditions are met

**URL:** <https://discuss.elastic.co/t/unable-to-trigger-a-watcher-alert-when-multiple-conditions-are-met/319361>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [November 20, 2022, 9:40am UTC](https://discuss.elastic.co/t/unable-to-trigger-a-watcher-alert-when-multiple-conditions-are-met/319361 "2022-11-20T09:40:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![as-sre](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@as-sre](https://discuss.elastic.co/u/as-sre)\
**Post date:** [November 20, 2022, 9:40am UTC](https://discuss.elastic.co/t/unable-to-trigger-a-watcher-alert-when-multiple-conditions-are-met/319361/1 "2022-11-20T09:40:53Z")

</div>

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"`  
` }`  
` },`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 18, 2022, 7:54am UTC](https://discuss.elastic.co/t/unable-to-trigger-a-watcher-alert-when-multiple-conditions-are-met/319361/2 "2022-12-18T07:54:11Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 15, 2023, 4:05am UTC](https://discuss.elastic.co/t/unable-to-trigger-a-watcher-alert-when-multiple-conditions-are-met/319361/3 "2023-01-15T04:05:56Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 12, 2023, 4:06am UTC](https://discuss.elastic.co/t/unable-to-trigger-a-watcher-alert-when-multiple-conditions-are-met/319361/4 "2023-02-12T04:06:41Z")

</div>

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