# Multiple Condition Watcher

**URL:** <https://discuss.elastic.co/t/multiple-condition-watcher/67707>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [December 1, 2016, 5:31am UTC](https://discuss.elastic.co/t/multiple-condition-watcher/67707 "2016-12-01T05:31:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![agf](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@agf](https://discuss.elastic.co/u/agf)\
**Post date:** [December 1, 2016, 5:31am UTC](https://discuss.elastic.co/t/multiple-condition-watcher/67707/1 "2016-12-01T05:31:43Z")

</div>

I have a watcher that is configured to monitor 2 inputs. The payload of input 1 is compared with the payload of input 2. I want to set the watch condition such that if the payload of input 1 != payload of input 2, check first that the payload of input 1 is not empty before sending out an email notification.

The reason for this is because the e-mail template for the watcher is populated with values based on the payload of input 1 and I don't want the watcher to send out notification emails where the contents are empty because the payload of input 1 is empty. So in this case, I imagine that some kind of multiple condition watcher needs to be configured but I'm not so sure how to set such a thing up. Any ideas on how to implement something like this?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 1, 2016, 9:07am UTC](https://discuss.elastic.co/t/multiple-condition-watcher/67707/2 "2016-12-01T09:07:09Z")

</div>

Hey,

if you paste your current watch and the data you are trying to query or write a condition for, it would be much easier to help, now everything is pretty abstract - I'll try my best though 🙂

So far, this sounds like you need to have a watch with a chained input, that gets the data for input1 and input2, then have a condition that checks if payload2 equals payload1 and is not empty, and based on that, sent out the email.

By using a [script condition](https://www.elastic.co/guide/en/x-pack/5.0/condition-script.html) you can easily implement the above check.

--Alex

---

<div class="post-metadata">

**Author:** ![agf](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@agf](https://discuss.elastic.co/u/agf)\
**Post date:** [December 1, 2016, 9:26am UTC](https://discuss.elastic.co/t/multiple-condition-watcher/67707/3 "2016-12-01T09:26:12Z")

</div>

Yup, I'm currently using a chained input for my watcher. Would it be possible for you to provide an example script condition that can implement what I'm trying to do?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 1, 2016, 1:28pm UTC](https://discuss.elastic.co/t/multiple-condition-watcher/67707/4 "2016-12-01T13:28:10Z")

</div>

```auto
POST _xpack/watcher/watch/_execute
{
  "watch": {
    "trigger": {
      "schedule": {
        "interval": "1h"
      }
    },
    "input": {
      "chain": {
        "inputs": [
          {
            "first": {
              "simple": {
                "foo": "bar"
              }
            }
          },
          {
            "second": {
              "simple": {
                "foo": "bar"
              }
            }
          }
        ]
      }
    },
    "condition": {
      "script": {
        "inline": "ctx.payload.first == ctx.payload.second"
      }
    },
    "actions": {
      "my_log": {
        "logging": {
          "text": "EQUALITY"
        }
      }
    }
  }
}

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![agf](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@agf](https://discuss.elastic.co/u/agf)\
**Post date:** [December 7, 2016, 9:16am UTC](https://discuss.elastic.co/t/multiple-condition-watcher/67707/5 "2016-12-07T09:16:31Z")

</div>

Hi @spinscale thanks for the reply. In the end, I used a totally different approach to implement my watcher. Appreciate the answer though.

---

<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 4, 2017, 9:16am UTC](https://discuss.elastic.co/t/multiple-condition-watcher/67707/6 "2017-01-04T09:16:32Z")

</div>

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