Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2010 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/512957 to your computer and use it in GitHub Desktop.
Save anonymous/512957 to your computer and use it in GitHub Desktop.
Facter.add("is_loghost") do
require 'resolv'
soas = []
loghosts = []
domain = Facter.value( :domain )
myname = Facter.value( :fqdn )
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
is_loghost=0
loghosts.each do |host|
if (host == myname)
is_loghost = 1
end
end
setcode do
is_loghost
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment