Browse Source

added default value to arguments, env and vars and moved check to the template.

Signed-off-by: Nick Chappell <nick@intronic.org>

Merged in from: https://github.com/Icinga/puppet-icinga2/pull/33

refs#7215: https://dev.icinga.org/issues/7215
Ricardo Melo 9 năm trước cách đây
mục cha
commit
4dfe6fa664
2 tập tin đã thay đổi với 11 bổ sung17 xóa
  1. 6 12
      manifests/object/eventcommand.pp
  2. 5 5
      templates/object_eventcommand.conf.erb

+ 6 - 12
manifests/object/eventcommand.pp

@@ -15,9 +15,9 @@ define icinga2::object::eventcommand (
 /*  $methods           = undef, */ /* Need to get more details about this attribute */
   $command           = undef,
   $cmd_path          = 'PluginDir',
-  $arguments         = undef,
-  $env               = undef,
-  $vars              = undef,
+  $arguments         = {},
+  $env               = {},
+  $vars              = {},
   $timeout           = undef,
   $target_dir        = '/etc/icinga2/objects/eventcommands',
   $target_file_name  = "${name}.conf",
@@ -31,15 +31,9 @@ define icinga2::object::eventcommand (
   validate_string($template_to_import)
   validate_array($command)
   validate_string($cmd_path)
-  if $arguments {
-    validate_hash($arguments)
-  }
-  if $env {
-    validate_hash($env)
-  }
-  if $vars {
-    validate_hash($vars)
-  }
+  validate_hash($arguments)
+  validate_hash($env)
+  validate_hash($vars)
   if $timeout {
     validate_re($timeout, '^\d+$')
   }

+ 5 - 5
templates/object_eventcommand.conf.erb

@@ -15,14 +15,14 @@ object EventCommand "<%= @object_eventcommandname %>" {
 
   <%- if @template_to_import -%>
   import "<%= @template_to_import -%>"
-
   <%- end -%>
   <%- if @command -%>
+
   command = [ <% if @cmd_path -%><%= @cmd_path -%> + <% end -%><% @command.each_with_index do |cmd, i| %><%= cmd -%><%= ', ' if i < (@command.size - 1) %><% end %> ]
   <%- end -%>
   <%#- Need to add support to argument value as hash (recursivity) -%>
+  <%- if @arguments.empty? != true -%>
 
-  <%- if @arguments -%>
   arguments = {
   <%- @arguments.each_with_index do |(key,value), i| -%>
     <%= key %> = <% if value.class == String %><%= value %>
@@ -35,8 +35,8 @@ object EventCommand "<%= @object_eventcommandname %>" {
   <%- end -%>
   }
   <%- end -%>
+  <%- if @vars.empty? -%>
 
-  <%- if @vars -%>
   <%- @vars.each_pair do |key,value| -%>
   <%= key %> = <% if value.class == String %><%= value %>
   <%- else -%>{
@@ -47,12 +47,12 @@ object EventCommand "<%= @object_eventcommandname %>" {
     <%- end -%>
   <%- end -%>
   <%- end -%>
-
   <%- if @timeout -%>
+
   timeout = <%= @timeout %>
   <%- end -%>
+  <%- if @env.empty? != true -%>
 
-  <%- if @env -%>
   env = {
   <%- @env.each_pair do |key,value| -%>
     <%= key %> = <%= value %>