# Tutorial for creating watcher scripts in Painless lab

**URL:** <https://discuss.elastic.co/t/tutorial-for-creating-watcher-scripts-in-painless-lab/248815>\
**Category:** Kibana\
**Created:** [September 16, 2020, 10:16am UTC](https://discuss.elastic.co/t/tutorial-for-creating-watcher-scripts-in-painless-lab/248815 "2020-09-16T10:16:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Babadofar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babadofar/32/44803_2.png) [@Babadofar](https://discuss.elastic.co/u/Babadofar)\
**Post date:** [September 16, 2020, 10:16am UTC](https://discuss.elastic.co/t/tutorial-for-creating-watcher-scripts-in-painless-lab/248815/1 "2020-09-16T10:16:57Z")

</div>

Not sure where this question really belongs, but anyway.  
Creating complex alerts in watcher, using multi level aggregations and painless scripts for the condition is a little unwieldy.  
The Painless Lab could be used to develop and test these scripts. But some guidance is needed. How to convert aggregations result into painless syntax? Some tool to do that - and some tutorial - would be appreciated.

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [September 17, 2020, 6:36am UTC](https://discuss.elastic.co/t/tutorial-for-creating-watcher-scripts-in-painless-lab/248815/2 "2020-09-17T06:36:52Z")

</div>

Hi

There is currently no watcher context available in the Painless lab, I agree this would be useful, and more selectable contexts might be provided in the future

What you could do is use the Lab to debug your script by e.g. defining a custom `ctx` before the actual script you want to test. So you'd need to create a context inside the painless script, but of course this might be complicated. But that's the way I've debugged ruby scripts for Logstash a while ago.

Best,  
Matthias

---

<div class="post-metadata">

**Author:** ![Babadofar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babadofar/32/44803_2.png) [@Babadofar](https://discuss.elastic.co/u/Babadofar)\
**Post date:** [September 21, 2020, 11:16am UTC](https://discuss.elastic.co/t/tutorial-for-creating-watcher-scripts-in-painless-lab/248815/3 "2020-09-21T11:16:54Z")

</div>

Ok I will create a custom `ctx` while waiting then. Thanks 🙂

---

<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:** [October 19, 2020, 11:16am UTC](https://discuss.elastic.co/t/tutorial-for-creating-watcher-scripts-in-painless-lab/248815/4 "2020-10-19T11:16:59Z")

</div>

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