Last active
August 29, 2015 14:13
-
-
Save dayglojesus/0297a023f37ab884e05a to your computer and use it in GitHub Desktop.
Facter: 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
# Edit the target variable to point to your AD domain | |
# Adjust timeout (less than max_timeout) and port as appropriate. | |
# Could be used to test any service really... | |
# | |
# We return Strings, strange? Yes. Facter doesn't like booleans and Hiera can't interpolate | |
# anything other than strings. | |
# Everything in Strings! | |
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 = 'your.ad.com' | |
timeout = 7 | |
port = 389 | |
max_timeout = 60 | |
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