# Watcher one field value in a json array

**URL:** <https://discuss.elastic.co/t/watcher-one-field-value-in-a-json-array/215642>\
**Category:** Kibana\
**Tags:** elastic-stack-alerting\
**Created:** [January 19, 2020, 6:40pm UTC](https://discuss.elastic.co/t/watcher-one-field-value-in-a-json-array/215642 "2020-01-19T18:40:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newtoelastic](https://avatars.discourse-cdn.com/v4/letter/n/8baadc/32.png) [@Newtoelastic](https://discuss.elastic.co/u/Newtoelastic)\
**Post date:** [January 19, 2020, 6:40pm UTC](https://discuss.elastic.co/t/watcher-one-field-value-in-a-json-array/215642/1 "2020-01-19T18:40:34Z")

</div>

Hey there, I am **really** new to Watcher and I was hoping someone could answer my question and help me as much as they can.

I am looking to set a watcher that will tell me when a DNS response name has been found in my "links" field. If they are a match than it should log / send email etc.

My question is, can a watcher find if the response is contained in the array? And if so how exactly would one go about writing a watcher like that.  
I read a bit about the chain watcher ability where I can basically search two different queries and if they match I can then alarm based on it. I took the skeleton that looks something along the lines of this but I am really unsure this will work :\

> {  
> "trigger": {  
> "schedule": {  
> "interval": "1m"  
> }  
> },  
> "input": {  
> "chain": {  
> "inputs": [  
> {  
> "first": {  
> "simple": {  
> "Links": "_"  
> }  
> }  
> }  
> },  
> {  
> "second": {  
> "simple": {  
> "dns.question.name": "_"  
> }  
> }  
> }  
> ]  
> }  
> },  
> "condition": {  
> "script": {  
> "source": "return ctx.payload.second.value.equals(ctx.payload.first.value)"  
> }  
> },  
> "actions": {  
> "log": {  
> "logging": {  
> "text": "they are equal!"  
> }  
> }  
> }  
> }

My custom Json Array - "Links"

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/7/67e9c3e4e257b41f99d1e89332cd983fcfc135ca.png)

My field of dns response field  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/a/aad0fafe2e6900f90dc5c27d2c5353e667ade49a.png)

---

<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:** [January 20, 2020, 4:21pm UTC](https://discuss.elastic.co/t/watcher-one-field-value-in-a-json-array/215642/2 "2020-01-20T16:21:43Z")

</div>

Hey,

take a look at this example

```auto
POST _watcher/watch/_execute
{
  "watch": {
    "trigger": {
      "schedule": {
        "interval": "10h"
      }
    },
    "input": {
      "simple": {
        "first": {
          "dns": {
            "question": {
              "name": "example.org"
            }
          }
        },
        "second": {
          "links": [
            "https://www.test.de",
            "https://example.org/foo"
          ]
        }
      }
    },
    "condition": {
      "script": "return ctx.payload.second.links.stream().anyMatch(link -> link.contains(ctx.payload.first.dns.question.name))"
    },
    "actions": {
      "logme": {
        "logging": {
          "text": "{{ctx}}"
        }
      }
    }
  }
}

```

that should help to get you started

--Alex

---

<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 17, 2020, 4:21pm UTC](https://discuss.elastic.co/t/watcher-one-field-value-in-a-json-array/215642/3 "2020-02-17T16:21:47Z")

</div>

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