Puppet Function: graphite_aliases
- Defined in:
- lib/puppet/parser/functions/graphite_aliases.rb
- Function type:
- Ruby 3.x API
Overview
Transforms values returned by query_facts() into a bunch of File resources which can be fed to create_resources(). The goal is to maintain a subtree of symlinks in graphite, offering a fact-based classification of nodes.
Example:
create_resources('file', graphite_aliases(
query_facts(
'Class[Collectd]', [
'ec2_instance_type',
'lsbdistcodename',
'role',
'server_family',
'server_classification']),
'/srv/carbon/whisper'
)
)
File <| name == '/srv/carbon/whisper/aliases' |> {
purge => true,
recurse => true,
force => true,
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/parser/functions/graphite_aliases.rb', line 1 Puppet::Parser::Functions.newfunction( :graphite_aliases, :type => :rvalue, :doc => <<-EOS Transforms values returned by query_facts() into a bunch of File resources which can be fed to create_resources(). The goal is to maintain a subtree of symlinks in graphite, offering a fact-based classification of nodes. Example: create_resources('file', graphite_aliases( query_facts( 'Class[Collectd]', [ 'ec2_instance_type', 'lsbdistcodename', 'role', 'server_family', 'server_classification']), '/srv/carbon/whisper' ) ) File <| name == '/srv/carbon/whisper/aliases' |> { purge => true, recurse => true, force => true, } EOS ) do |args| dirlist = [] resources = {} prefix = args.pop args.pop.each do |host_dots, f| host = host_dots.gsub(/\./, '_') f.each do |k,v| fact_dir = "aliases/by-#{k}/#{v}".gsub(/\./, '_') dirlist << fact_dir resources["#{prefix}/#{fact_dir}/#{host}"] = { "ensure" => "symlink", "target" => "#{prefix}/collectd/#{host}", } end end basedirs = [] dirlist.uniq.each do |e| dirs = [] e.split(/\//).each {|d| dirs << "#{dirs.last}/#{d}" } basedirs << dirs end basedirs.flatten.uniq.each do |dir| resources["#{prefix}#{dir}"] = { "ensure" => "directory", } end resources end |