diff --git a/lib/puppet_x/icinga2/utils.rb b/lib/puppet_x/icinga2/utils.rb index 41d3570e8..1bd9b0ad6 100644 --- a/lib/puppet_x/icinga2/utils.rb +++ b/lib/puppet_x/icinga2/utils.rb @@ -72,10 +72,11 @@ module Utils def self.attributes(attrs, consts, indent=2) def self.value_types(value) + if value =~ /^\d+\.?\d*[dhms]?$/ || value =~ /^(true|false)$/ result = value else - if $constants.include?(value) || value =~ /^!?(host|service|user)\./ || value =~ /^\{{2}.*\}{2}$/ + if $constants.index { |x| value =~ /^!?(#{x})(\..+$|$)/ } || value =~ /^!?(host|service|user)\./ || value =~ /^\{{2}.*\}{2}$/ result = value else result = "\"#{value}\"" @@ -149,7 +150,6 @@ def self.process_hash(attrs, indent=2, level=3, prefix=' '*indent) end end elsif value.is_a?(Array) - #result += "%s%s = [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ] result += case level when 2 then "%s[\"%s\"] = [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ] else "%s%s = [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ] @@ -173,16 +173,15 @@ def self.process_hash(attrs, indent=2, level=3, prefix=' '*indent) # globals (params.pp) and all keys of attrs hash itselfs must not quoted $constants = consts.concat(attrs.keys) << "name" - # also with added not operetor '!' - $constants += $constants.map {|x| "!#{x}"} # initialize returned configuration config = '' attrs.each do |attr, value| + if attr =~ /^(assign|ignore) where$/ value.each do |x| - config += "%s%s %s\n" % [ ' ' * indent, attr, parse(x) ] + config += "%s%s %s\n" % [ ' ' * indent, attr, parse(x) ] if x != :undef end else if value.is_a?(Hash) @@ -194,7 +193,7 @@ def self.process_hash(attrs, indent=2, level=3, prefix=' '*indent) elsif value.is_a?(Array) config += "%s%s = [ %s]\n" % [ ' ' * indent, attr, process_array(value) ] else - config += "%s%s = %s\n" % [ ' ' * indent, attr, parse(value) ] if value != :undef + config += "%s%s = %s\n" % [ ' ' * indent, attr, parse(value) ] end end end diff --git a/manifests/params.pp b/manifests/params.pp index b0df41bbe..159fcf293 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -19,7 +19,6 @@ $plugins = [ 'plugins', 'plugins-contrib', 'windows-plugins', 'nscp' ] $default_features = [ 'checker', 'mainlog', 'notification' ] $globals = [ - '==', '!=', '!', '||', '&&', 'Acknowledgement', 'ApplicationType', 'AttachDebugger', diff --git a/spec/defines/object_spec.rb b/spec/defines/object_spec.rb index 31e60675e..ccb417b7c 100644 --- a/spec/defines/object_spec.rb +++ b/spec/defines/object_spec.rb @@ -79,23 +79,24 @@ end - context "#{os} with import => [bar, baz], apply => foo in host.vars.bar" do - let(:params) { {:import => ['bar', 'baz'], :apply => 'foo in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} } + context "#{os} with import => [bar, baz], apply => desc in host.vars.bar, assign => [desc.bar]" do + let(:params) { {:import => ['bar', 'baz'], :apply => 'desc in host.vars.bar', :apply_target => 'Host', :assign => ['desc.bar'], :attrs => {'vars' => 'vars + desc'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} } it { is_expected.to contain_concat__fragment('bar') .with_content(/import "bar"/) .with_content(/import "baz"/) - .with_content(/vars = vars \+ foo\n/) - .with_content(/apply foo for \(foo in host.vars.bar\) to Host/) } + .with_content(/vars = vars \+ desc\n/) + .with_content(/apply foo for \(desc in host.vars.bar\) to Host/) + .with_content(/assign where desc.bar/) } end - context "#{os} with apply => foo => config in host.vars.bar" do - let(:params) { {:apply => 'foo => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo + config'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} } + context "#{os} with apply => desc => config in host.vars.bar" do + let(:params) { {:apply => 'desc => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + desc + !config.bar'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} } it { is_expected.to contain_concat__fragment('bar') - .with_content(/vars = vars \+ foo \+ config\n/) - .with_content(/apply foo for \(foo => config in host.vars.bar\) to Host/) } + .with_content(/vars = vars \+ desc \+ !config.bar\n/) + .with_content(/apply foo for \(desc => config in host.vars.bar\) to Host/) } end @@ -329,23 +330,24 @@ end - context "Windows 2012 R2 with import => [bar, baz], apply => foo in host.vars.bar" do - let(:params) { {:import => ['bar', 'baz'], :apply => 'foo in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } + context "Windows with import => [bar, baz], apply => desc in host.vars.bar, assign => [desc.bar]" do + let(:params) { {:import => ['bar', 'baz'], :apply => 'desc in host.vars.bar', :apply_target => 'Host', :assign => ['desc.bar'], :attrs => {'vars' => 'vars + desc'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } it { is_expected.to contain_concat__fragment('bar') .with_content(/import "bar"/) .with_content(/import "baz"/) - .with_content(/vars = vars \+ foo\r\n/) - .with_content(/apply foo for \(foo in host.vars.bar\) to Host/) } + .with_content(/vars = vars \+ desc\r\n/) + .with_content(/apply foo for \(desc in host.vars.bar\) to Host/) + .with_content(/assign where desc.bar/) } end - context "Windows 2012 R2 with apply => foo => config in host.vars.bar" do - let(:params) { {:apply => 'foo => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo + config'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } + context "Windows 2012 R2 with apply => desc => config in host.vars.bar" do + let(:params) { {:apply => 'desc => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + desc + !config.bar'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } it { is_expected.to contain_concat__fragment('bar') - .with_content(/vars = vars \+ foo \+ config\r\n/) - .with_content(/apply foo for \(foo => config in host.vars.bar\) to Host/) } + .with_content(/vars = vars \+ desc \+ !config.bar\r\n/) + .with_content(/apply foo for \(desc => config in host.vars.bar\) to Host/) } end