shadabahmed / logstasher

Awesome rails logs
MIT License
818 stars 136 forks source link

Gem initialization not working on MacOS Sierra and later #131

Closed syndbg closed 7 years ago

syndbg commented 7 years ago

Due to Apple's changes in MacOS Sierra and later, hostnames are unresolvable by the code in https://github.com/shadabahmed/logstasher/commit/dda48f5a3a040c3e1e808ab3c0293e1c147929d6.

That's paritaly due to MacOS adding .local to the hostname and even when using the hostname -s to get the real hostname w/o .local, the hostname is still not resolving to an IP.

E.g

[1] pry(main)> hostname = Socket.gethostname
=> "Antons-MacBook-Pro.local"
[2] pry(main)> IPSocket.getaddress(hostname)
SocketError: getaddrinfo: nodename nor servname provided, or not known
finalwharf commented 7 years ago

The issue is not related to changes in Sierra. Also Sierra on the latest version of OS X!

On Mac OS X v10.2 an later, Logstasher fails to initialize. When loading its configs, both generic and env specific, it looks for a :source key.

config.source = yml_config[:source].present? ? yml_config[:source] : IPSocket.getaddress(Socket.gethostname)

IPSocket.getaddress fails because Socket.gethostname returns a .local domain name (e.g. zeus.local). OSX uses such domains along with mDNS to resolve Bonjour services on the local network.

Since Ruby has no notion of this service, it tries to resolve the hostname using regular (unicast) DNS, which fails.

syndbg commented 7 years ago

This is not specific to Ruby. The issue occurs on any other given language that uses POSIX libraries.

shadabahmed commented 7 years ago

Thanks for the PR. Closing this issue 👍

The fix is now available in version 1.2.1

chalvern commented 6 years ago

I fixed the issue by add the hostname in /etc/hosts.