DataDog / dogapi-rb

Ruby client for Datadog's API
https://www.datadoghq.com
BSD 3-Clause "New" or "Revised" License
96 stars 88 forks source link

Dont shell out to obtain hostname #39

Closed ranjib closed 10 years ago

ranjib commented 10 years ago
require 'socker'
Socket.gethostname

https://github.com/DataDog/dogapi-rb/blob/master/lib/dogapi/common.rb#L159

miketheman commented 10 years ago

@ranjib Did you mean require 'socket'? I don't think there's a 'socker' library in StdLib, but I do like the name. :grin:

As can be seen in the immediate preceding line there's a comment as to preferring the hostname command. Digging into history, this came from this commit ad322ce8e5f6844c54ace09d96fc3f10c0b8823f and further history shows the question and answer reasoning here: http://stackoverflow.com/a/12046321/244037 by our own @alq666.

Ohai shells out too, and has for years, probably due to the same problem.

Is there a particular reason shelling out isn't the way to go?

ranjib commented 10 years ago

:-( yeah i meant socket. on (1.9.x)[http://ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/Socket.html#method-c-gethostname] and (2.x)[http://ruby-doc.org/stdlib-2.0.0/libdoc/socket/rdoc/Socket.html#method-c-gethostname] its part of the stdlib. do you need fqdn or just the uts name? im trying to run our scripts with env -i flag (before we push our dd integration into our omnibus installer), does that make sense? any way i'll close the ticket, i was not sure why an http api client needs to shellout (ohai is a system discovery tool right?), if dependency on fqdn is a key requirement then i guess this is the right thing to do (but even in that case i'll prefer to accept this as an argument, instead of shelling out)