Multiple Condition Watcher

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?

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 :slight_smile:

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 you can easily implement the above check.

--Alex

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?

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

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

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