Skip to content

Instantly share code, notes, and snippets.

@dayglojesus
Created March 29, 2015 17:44
Show Gist options
  • Save dayglojesus/77e21406c5d08ad1ee1b to your computer and use it in GitHub Desktop.
Save dayglojesus/77e21406c5d08ad1ee1b to your computer and use it in GitHub Desktop.
Custom Facter Fact: domain_available?
# Change the value of the `target` variable
require 'puppet'
require 'socket'
require 'timeout'
Facter.add("domain_available?") do
confine :operatingsystem => :darwin
setcode do
class Ping
def self.pingecho(host, timeout=5, port=80)
begin
timeout(timeout) do
s = TCPSocket.new(host, port)
s.close
end
rescue Errno::ECONNREFUSED
return "false"
rescue Timeout::Error, StandardError
return "false"
end
return "true"
end
end
target = 'some.domain.com'
timeout = 7
port = 389
max_timeout = 15
begin
Timeout::timeout(max_timeout) do
Ping.pingecho target, timeout, port
end
rescue Timeout::Error
return "false"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment