How can i get the hostname of linux server using logstash


(Ganesh) #1

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.


(Ganesh) #2

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


(system) #3

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