# How can I get the logstash hostname

**URL:** <https://discuss.elastic.co/t/how-can-i-get-the-logstash-hostname/51771>\
**Category:** Logstash\
**Created:** [June 3, 2016, 8:30am UTC](https://discuss.elastic.co/t/how-can-i-get-the-logstash-hostname/51771 "2016-06-03T08:30:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericpietro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericpietro/32/9685_2.png) [@ericpietro](https://discuss.elastic.co/u/ericpietro)\
**Post date:** [June 3, 2016, 8:30am UTC](https://discuss.elastic.co/t/how-can-i-get-the-logstash-hostname/51771/1 "2016-06-03T08:30:33Z")

</div>

Hi,

logstash add a field named 'host' that contains the source hostname in the input section.  
but how can I get the hostname where logstash is curently running ?

ty

---

<div class="post-metadata">

**Author:** ![ericpietro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericpietro/32/9685_2.png) [@ericpietro](https://discuss.elastic.co/u/ericpietro)\
**Post date:** [June 10, 2016, 1:57pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-logstash-hostname/51771/2 "2016-06-10T13:57:21Z")

</div>

i'm always asking for this question ... anybody can help ?  
ty 🙂

---

<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:** [June 14, 2016, 6:13pm UTC](https://discuss.elastic.co/t/how-can-i-get-the-logstash-hostname/51771/3 "2016-06-14T18:13:25Z")

</div>

```nohighlight
filter {
  ruby {
    init => "require 'socket'"
    code => "event['some-field-name'] = Socket.gethostname"
  }
}

```

---

<div class="post-metadata">

**Author:** ![ericpietro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericpietro/32/9685_2.png) [@ericpietro](https://discuss.elastic.co/u/ericpietro)\
**Post date:** [June 15, 2016, 10:06am UTC](https://discuss.elastic.co/t/how-can-i-get-the-logstash-hostname/51771/4 "2016-06-15T10:06:09Z")

</div>

ty very much magnus 🙂

---

<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, 4:52am UTC](https://discuss.elastic.co/t/how-can-i-get-the-logstash-hostname/51771/5 "2017-07-06T04:52:44Z")

</div>


