Created
March 29, 2015 17:44
-
-
Save dayglojesus/77e21406c5d08ad1ee1b to your computer and use it in GitHub Desktop.
Custom Facter Fact: domain_available?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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