# How tcp input add fields?

**URL:** <https://discuss.elastic.co/t/how-tcp-input-add-fields/48164>\
**Category:** Logstash\
**Created:** [April 22, 2016, 12:22pm UTC](https://discuss.elastic.co/t/how-tcp-input-add-fields/48164 "2016-04-22T12:22:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iyaozhen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iyaozhen/32/7276_2.png) [@iyaozhen](https://discuss.elastic.co/u/iyaozhen)\
**Post date:** [April 22, 2016, 12:22pm UTC](https://discuss.elastic.co/t/how-tcp-input-add-fields/48164/1 "2016-04-22T12:22:19Z")

</div>

I use python tail log file, and publish to logstash(tcp input).

Because my system problem([#46708](https://discuss.elastic.co/t/loading-config-file-error-open-filebeat-yml-function-not-implemented/46708)), I can't use `filebeat`, and filebeat have a very useful setting `fields`.

How can I achieve this features by python.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 24, 2016, 12:01am UTC](https://discuss.elastic.co/t/how-tcp-input-add-fields/48164/2 "2016-04-24T00:01:32Z")

</div>

You would either need to use the `add_fields` option in the input, or use grok.

---

<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:** [April 24, 2016, 5:13pm UTC](https://discuss.elastic.co/t/how-tcp-input-add-fields/48164/3 "2016-04-24T17:13:26Z")

</div>

I suggest that you instead of sending the raw log file contents construct JSON strings containing whatever fields you like (including one field with the log message) and send _that_ to Logstash. Use a json (or json\_lines?) codec to deserialize the JSON string.

---

<div class="post-metadata">

**Author:** ![iyaozhen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iyaozhen/32/7276_2.png) [@iyaozhen](https://discuss.elastic.co/u/iyaozhen)\
**Post date:** [April 25, 2016, 4:00am UTC](https://discuss.elastic.co/t/how-tcp-input-add-fields/48164/4 "2016-04-25T04:00:34Z")

</div>

Yes, you are right. Thank for your suggest.

---

<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:00am UTC](https://discuss.elastic.co/t/how-tcp-input-add-fields/48164/5 "2017-07-06T05:00:51Z")

</div>


