summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Seely <justin.seely@gmail.com>2017-09-09 03:55:34 +0000
committervijaymmali1990 <vijay.mali@msystechnologies.com>2018-11-28 12:12:29 +0530
commit8ef11a7b494b16446f324af9903ca7c729db03f2 (patch)
treeb9ad41a8f1334f981e34282e26042b4ba65916da
parentaf633604e28442884b131dd51a09738251d5f2b6 (diff)
downloadohai-8ef11a7b494b16446f324af9903ca7c729db03f2.tar.gz
Check all associated host addresses for FQDNs instead of just the last
Signed-off-by: Justin Seely <justin.seely@gmail.com>
-rw-r--r--lib/ohai/plugins/hostname.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 0f103c5d..15d19091 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -173,9 +173,20 @@ Ohai.plugin(:Hostname) do
if info.first =~ /.+?\.(.*)/
fqdn info.first
else
- # host is not in dns. optionally use:
- # C:\WINDOWS\system32\drivers\etc\hosts
- fqdn Socket.gethostbyaddr(info.last).first
+ #host is not in dns. optionally use:
+ #C:\WINDOWS\system32\drivers\etc\hosts
+ found_fqdn = false
+ info[3..info.length].reverse.each do |addr|
+ hostent = Socket.gethostbyaddr(addr)
+ if hostent.first =~ /.+?\.(.*)/
+ fqdn hostent.first
+ found_fqdn = true
+ break
+ end
+ end
+ if !found_fqdn
+ fqdn info.first
+ end
end
domain collect_domain
end