# How can i get the hostname of linux server using logstash

**URL:** <https://discuss.elastic.co/t/how-can-i-get-the-hostname-of-linux-server-using-logstash/156480>\
**Category:** Logstash\
**Created:** [November 13, 2018, 1:32pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-hostname-of-linux-server-using-logstash/156480 "2018-11-13T13:32:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [November 13, 2018, 1:32pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-hostname-of-linux-server-using-logstash/156480/1 "2018-11-13T13:32:12Z")

</div>

HI,  
My logstash is running on 2 different linux server and i want to find which logstash server logs are getting into index by adding hostname field. I tried with below ruby code and getting error on that. Anyone can help me out of this,

```
ruby {
                init => "require 'socket'"
                code => "event['server_hostname'] = Socket.gethostname"
        }

```

error:

`[2018-11-13T13:25:48,171][ERROR][logstash.filters.ruby] Ruby exception occurred: Direct event field references (i.e. event['field'] = 'value') have been disabled in favor of using event get and set methods (e.g. event.set('field', 'value')). Please consult the Logstash 5.0 breaking changes documentation for more details.`

---

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [November 13, 2018, 1:44pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-hostname-of-linux-server-using-logstash/156480/2 "2018-11-13T13:44:59Z")

</div>

I could achieve this using below condition,

```
ruby {
init => "require 'socket'"
code => "event.set('some field', Socket.gethostname)"
}

```

but im using docker container to run logstash when i execute this filter, my new field is get created and it contains my container id instead of hostname

---

<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:** [December 11, 2018, 1:51pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-hostname-of-linux-server-using-logstash/156480/3 "2018-12-11T13:51:10Z")

</div>

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