# Filebeat Processors - Can i condition between two vars?

**URL:** <https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [May 7, 2021, 6:05am UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367 "2021-05-07T06:05:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronh](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@ronh](https://discuss.elastic.co/u/ronh)\
**Post date:** [May 7, 2021, 6:05am UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367/1 "2021-05-07T06:05:03Z")

</div>

Hello,

Is it possible to compare between 2 vars in input data?

For example:

```auto
processors:
  - add_host_metadata:
      netinfo.enabled: true

  - if:
      contains:
        host.ip: $source.ip
    then:
      - add_fields:
          target: communication
          fields:
            type: internal

```

source.ip is a field on input data.  
host.ip created in add\_host\_metadata.

In this example, I got from the input event the source IP and I will happy to check if the IP address exists in host.ip (add\_host\_metadata) to determine if the IP address is internal address.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![legoguy1000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/legoguy1000/32/54301_2.png) [@legoguy1000](https://discuss.elastic.co/u/legoguy1000)\
**Post date:** [May 7, 2021, 9:25am UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367/2 "2021-05-07T09:25:49Z")

</div>

U could try `{{source.ip}}`. That's how u reference a field value in the ingest processors but idk if it will work in the beats processors. I tried looking in GitHub for an example but wasn't able to find one.

---

<div class="post-metadata">

**Author:** ![ronh](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@ronh](https://discuss.elastic.co/u/ronh)\
**Post date:** [May 7, 2021, 10:03am UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367/3 "2021-05-07T10:03:53Z")

</div>

Thank you for your answer.  
Unfortunately, It doesn't work. ☹

---

<div class="post-metadata">

**Author:** ![legoguy1000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/legoguy1000/32/54301_2.png) [@legoguy1000](https://discuss.elastic.co/u/legoguy1000)\
**Post date:** [May 7, 2021, 10:45am UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367/4 "2021-05-07T10:45:34Z")

</div>

Based on another forum post, I'd say your best bet to do this is using logstash or an ingest pipeline.

---

<div class="post-metadata">

**Author:** ![ronh](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@ronh](https://discuss.elastic.co/u/ronh)\
**Post date:** [May 7, 2021, 1:23pm UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367/6 "2021-05-07T13:23:55Z")

</div>

Thanks 🙂

Can I use javascript processors script?  
I tried to write a function to find a solution:

```auto
processors:
  - add_host_metadata:
      netinfo.enabled: true

  - script:
      lang: javascript
      id: my_filter

      source: >
        function process(event) {
            var ips = event.Get("host.ip");
            var src_ip = event.Get('source.ip');
            if (ips.includes(src_ip)) {
                event.Tag("internal");
            }
            return event;
        }

```

But I got the exception when I try to check if source IP exists in ips array (host.ip --\> host metadata)

```auto
"message": "TypeError: Object has no member 'includes' at process (inline.js:4:21(19))"

```

Did anyone get this javescript exception?

---

<div class="post-metadata">

**Author:** ![legoguy1000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/legoguy1000/32/54301_2.png) [@legoguy1000](https://discuss.elastic.co/u/legoguy1000)\
**Post date:** [May 7, 2021, 2:07pm UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367/7 "2021-05-07T14:07:08Z")

</div>

Hmm, take a look at the other JS scripts. Try `ips.indexOf(xxx) !== -1`

---

<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 4, 2021, 4:07pm UTC](https://discuss.elastic.co/t/filebeat-processors-can-i-condition-between-two-vars/272367/8 "2021-06-04T16:07:39Z")

</div>

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