Puppet Function: collectd_convert_processes
- Defined in:
- lib/puppet/parser/functions/collectd_convert_processes.rb
- Function type:
- Ruby 3.x API
Overview
Converts the array from the old style to define process or processmatch in the processes plugin into a create_resources compatible hash which can be used with the new style define.
Example:
[ { 'name' => 'foo', 'regex' => '.*' } , { 'name' => 'bar', 'regex' => '[0-9]+' }, "alone" ]
will be converted to
{ 'foo' => { 'regex' => '.*' } , 'bar' => { 'regex' => '[0-9]+' }, 'alone' => {} }
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 |
# File 'lib/puppet/parser/functions/collectd_convert_processes.rb', line 3 Puppet::Parser::Functions.newfunction(:collectd_convert_processes, type: :rvalue, arity: 1, doc: <<-ENDDOC Converts the array from the old style to define process or processmatch in the processes plugin into a create_resources compatible hash which can be used with the new style define. Example: [ { 'name' => 'foo', 'regex' => '.*' } , { 'name' => 'bar', 'regex' => '[0-9]+' }, "alone" ] will be converted to { 'foo' => { 'regex' => '.*' } , 'bar' => { 'regex' => '[0-9]+' }, 'alone' => {} } ENDDOC ) do |args| raise(Puppet::ParseError, 'convert_process_array(): Needs exactly one argument') if args.size != 1 if args[0].is_a?(Hash) return args[0] # Keep normal hiera hash as-is end parray = args[0] raise(Puppet::ParseError, 'convert_process_array(): Needs an array as argument') unless parray.is_a?(Array) phash = {} parray.each do |p| case p when String phash[p] = {} when Hash name = p.delete('name') phash[name] = p else raise(Puppet::ParseError, 'convert_process_array(): array element must be string or hash') end end return phash end |