[icinga-checkins] icinga.org: puppet-icinga2/develop: Fix notificationcommand template

git at icinga.org git at icinga.org
Tue Aug 2 14:47:27 CEST 2016


Module: puppet-icinga2
Branch: develop
Commit: 556db546d6137b077be36141f8c463b6990aaef5
URL:    https://git.icinga.org/?p=puppet-icinga2.git;a=commit;h=556db546d6137b077be36141f8c463b6990aaef5

Author: Stefan Kleindl <stefan.kleindl at rise-world.com>
Date:   Thu Jul  7 13:10:36 2016 +0200

Fix notificationcommand template

Make sure the "command" parameter is passed as an array to the
"each_with_index" method, otherwise an exeption is thrown.

Minor syntax corrections and spec test adjustment.

---

 .../icinga2__object/notificationcommand_spec.rb       |   17 +++++++++++++++++
 templates/object/notificationcommand.conf.erb         |    7 ++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/spec/defines/icinga2__object/notificationcommand_spec.rb b/spec/defines/icinga2__object/notificationcommand_spec.rb
index 10a9682..9f53ce4 100644
--- a/spec/defines/icinga2__object/notificationcommand_spec.rb
+++ b/spec/defines/icinga2__object/notificationcommand_spec.rb
@@ -26,6 +26,23 @@ describe 'icinga2::object::notificationcommand' do
     pending
   end
 
+  context "with parameter command = string" do
+
+    let(:title) { 'testnotificationcommand' }
+
+    let(:params) do
+      {
+        :object_notificationcommandname => 'testnotificationcommand',
+        :command => 'testcommand1'
+      }
+    end
+
+    object_file = '/etc/icinga2/objects/notificationcommands/testnotificationcommand.conf'
+    it { should contain_icinga2__object__notificationcommand('testnotificationcommand') }
+    it { should contain_file(object_file).with_content(/^\s*command = \[ PluginDir \+ "testcommand1" \]$/) }
+
+  end
+
   context "with parameter command = array with one item" do
 
     let(:title) { 'testnotificationcommand' }
diff --git a/templates/object/notificationcommand.conf.erb b/templates/object/notificationcommand.conf.erb
index 4d2bb82..cf033b7 100644
--- a/templates/object/notificationcommand.conf.erb
+++ b/templates/object/notificationcommand.conf.erb
@@ -16,7 +16,8 @@ object NotificationCommand "<%= @object_notificationcommandname %>" {
   <%- end -%>
   <%- if @command -%>
 
-  command = [ <% @command.each_with_index do |cmd, i| %><% if @cmd_path -%><%= @cmd_path -%> + <% end -%>"<%= cmd -%>"<%= ', ' if i < (@command.size - 1) %><% end %> ]
+  <%- a_command = [@command].flatten.compact -%>
+  command = [ <% a_command.each_with_index do |cmd, i| %><% if @cmd_path -%><%= @cmd_path -%> + <% end -%>"<%= cmd -%>"<%= ', ' if i < (a_command.size - 1) %><% end %> ]
   <%- end -%>
   <%- if @arguments.any? -%>
 
@@ -24,7 +25,7 @@ object NotificationCommand "<%= @object_notificationcommandname %>" {
   <%- end -%>
   <%- if @vars.any? -%>
 
-  vars += <%= scope.function_icinga2_config_value([@vars]) %>
+  vars = <%= scope.function_icinga2_config_value([@vars]) %>
   <%- end -%>
   <%- if @timeout -%>
 
@@ -32,6 +33,6 @@ object NotificationCommand "<%= @object_notificationcommandname %>" {
   <%- end -%>
   <%- if @env.any? -%>
 
-  env += <%= scope.function_icinga2_config_value([@env]) %>
+  env = <%= scope.function_icinga2_config_value([@env]) %>
   <%- end -%>
 }



More information about the icinga-checkins mailing list