Skip to content

Instantly share code, notes, and snippets.

@handyman5
Created October 13, 2011 08:51
Show Gist options
  • Save handyman5/1283770 to your computer and use it in GitHub Desktop.
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
#!/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