Created
October 13, 2011 08:51
-
-
Save handyman5/1283770 to your computer and use it in GitHub Desktop.
Custom fact for figuring out which Ganglia grid a given host goes in
This file contains 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
#!/usr/bin/ruby | |
# grid.rb | |
def find_grid(hostname) | |
grid = "admin" | |
if hostname =~ (/^(build|launch|util)\d{1,4}/) | |
grid = $1 | |
elsif hostname =~ (/^www\d{1,4}/) | |
grid = "web" | |
end | |
return grid | |
end | |
if __FILE__ == $0 | |
if ARGV[0] | |
print find_grid(ARGV[0]), "\n" | |
end | |
else | |
begin | |
Facter.hostname | |
rescue | |
Facter.loadfacts() | |
end | |
hostname = Facter.value("hostname") | |
grid = find_grid(hostname) | |
Facter.add("grid") do | |
setcode do | |
grid | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment