# Kibana Watcher - Using it to calculate a percentage of two result values

**URL:** <https://discuss.elastic.co/t/kibana-watcher-using-it-to-calculate-a-percentage-of-two-result-values/273305>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [May 18, 2021, 2:45pm UTC](https://discuss.elastic.co/t/kibana-watcher-using-it-to-calculate-a-percentage-of-two-result-values/273305 "2021-05-18T14:45:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zooka94](https://avatars.discourse-cdn.com/v4/letter/z/b5e925/32.png) [@Zooka94](https://discuss.elastic.co/u/Zooka94)\
**Post date:** [May 18, 2021, 2:45pm UTC](https://discuss.elastic.co/t/kibana-watcher-using-it-to-calculate-a-percentage-of-two-result-values/273305/1 "2021-05-18T14:45:19Z")

</div>

I am trying to use a watcher to parse email event data, we have a field that will state if the email delivery is successful/delayed/ failed.

I want to know if it is possible to calculate the percentage of failed messages vs the successful for example.

For example, I would want to run a script following this route:

```auto
    "condition": {
      "script": {
          "source": "return (ctx.payload.traffic.hits.hits._source.dsnAction.failed * 100 / ctx.payload.traffic.hits.total) >= 2",
            "lang": "painless"        
        }
    }

```

Is this possible? `ctx.payload.traffic.hits.hits._source.dsnAction.failed` is an example

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:** [June 15, 2021, 2:45pm UTC](https://discuss.elastic.co/t/kibana-watcher-using-it-to-calculate-a-percentage-of-two-result-values/273305/2 "2021-06-15T14:45:39Z")

</div>

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