# Filter by port using pipe directive

**URL:** <https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688>\
**Category:** Logstash\
**Created:** [October 6, 2015, 11:31am UTC](https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688 "2015-10-06T11:31:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben19](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben19/32/3745_2.png) [@Ben19](https://discuss.elastic.co/u/Ben19)\
**Post date:** [October 6, 2015, 11:31am UTC](https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688/1 "2015-10-06T11:31:31Z")

</div>

Hello, I’m attempting to collect sflow logs from a number of  
exporters that will be exporting and sending the traffic on UDP port 6434. I’m  
using the pipe directive since I can specify the command setting, otherwise I’d  
simply use the UDP directive with the port setting etc.

My issue is how would I differentiate this traffic from  
other inputs? I don’t want to be use the IF [host] setting since I want to  
syslog traffic from these hosts too on UDP 514.

My input .conf is below:

> input {  
> pipe {  
> type =\> "sflow"  
> command =\> "/usr/local/bin/sflowtool\_wrapper.sh -l -p 6343"  
> }  
> }

Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 6, 2015, 12:25pm UTC](https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688/2 "2015-10-06T12:25:36Z")

</div>

You mean you have other inputs that also use the sflow type? Consider adding a tag that differentiates these sflow messages from other sflow messages.

```
input {
  pipe {
    type => "sflow"
    command => "/usr/local/bin/sflowtool_wrapper.sh -l -p 6343"
    tags => ["mytag"]
  }
}

```

Then use a conditional on the `tags` field in your filter and/or output blocks:

```
if "mytag" in [tags] {
  ...
}
```

---

<div class="post-metadata">

**Author:** ![Ben19](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben19/32/3745_2.png) [@Ben19](https://discuss.elastic.co/u/Ben19)\
**Post date:** [October 6, 2015, 12:35pm UTC](https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688/3 "2015-10-06T12:35:48Z")

</div>

We use NetFlow and Syslog which is sent to different  
indexes, both are defined by the port.

This would be the first sflow input.

---

<div class="post-metadata">

**Author:** ![Ben19](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben19/32/3745_2.png) [@Ben19](https://discuss.elastic.co/u/Ben19)\
**Post date:** [October 8, 2015, 2:24pm UTC](https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688/4 "2015-10-08T14:24:31Z")

</div>

So I would be happy to use the tags directive but that won't differentiate the ports.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 8, 2015, 2:40pm UTC](https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688/5 "2015-10-08T14:40:47Z")

</div>

Is there a field containing the port number, or how is Logstash supposed to know about the ports that come into play?

---

<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:** [July 6, 2017, 5:27am UTC](https://discuss.elastic.co/t/filter-by-port-using-pipe-directive/31688/6 "2017-07-06T05:27:08Z")

</div>


