Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2010 12:24
Show Gist options
  • Save anonymous/512755 to your computer and use it in GitHub Desktop.
Save anonymous/512755 to your computer and use it in GitHub Desktop.
Facter.add("loghost_list") do
require 'resolv'
soas = []
loghosts = []
domain = Facter.value( :domain )
res = Resolv::DNS::new('/etc/resolv.conf')
nameservers = res.getresources( domain, Resolv::DNS::Resource::IN::NS)
nameservers.each { |x| soas.push(Resolv.getaddress(x.name.to_s) ) }
ares = Resolv::DNS::new( { :nameserver => soas, :search => [ domain ], :ndots => 1 } )
ares.each_resource(['loghost',domain].join('.'), Resolv::DNS::Resource::IN::ANY) do |r|
if r.kind_of?(Resolv::DNS::Resource::IN::A) then
loghosts.push(r.name.to_s)
elsif r.kind_of?(Resolv::DNS::Resource::CNAME) then
loghosts.push(r.name.to_s)
end
end
loghost_list=loghosts.join(":");
if loghost
loghost
else
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment