Skip to content
This repository was archived by the owner on Apr 16, 2018. It is now read-only.

Commit 556db54

Browse files
n00byarioch
authored andcommitted
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.
1 parent c467ad9 commit 556db54

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

spec/defines/icinga2__object/notificationcommand_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
pending
2727
end
2828

29+
context "with parameter command = string" do
30+
31+
let(:title) { 'testnotificationcommand' }
32+
33+
let(:params) do
34+
{
35+
:object_notificationcommandname => 'testnotificationcommand',
36+
:command => 'testcommand1'
37+
}
38+
end
39+
40+
object_file = '/etc/icinga2/objects/notificationcommands/testnotificationcommand.conf'
41+
it { should contain_icinga2__object__notificationcommand('testnotificationcommand') }
42+
it { should contain_file(object_file).with_content(/^\s*command = \[ PluginDir \+ "testcommand1" \]$/) }
43+
44+
end
45+
2946
context "with parameter command = array with one item" do
3047

3148
let(:title) { 'testnotificationcommand' }

templates/object/notificationcommand.conf.erb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@ object NotificationCommand "<%= @object_notificationcommandname %>" {
1616
<%- end -%>
1717
<%- if @command -%>
1818

19-
command = [ <% @command.each_with_index do |cmd, i| %><% if @cmd_path -%><%= @cmd_path -%> + <% end -%>"<%= cmd -%>"<%= ', ' if i < (@command.size - 1) %><% end %> ]
19+
<%- a_command = [@command].flatten.compact -%>
20+
command = [ <% a_command.each_with_index do |cmd, i| %><% if @cmd_path -%><%= @cmd_path -%> + <% end -%>"<%= cmd -%>"<%= ', ' if i < (a_command.size - 1) %><% end %> ]
2021
<%- end -%>
2122
<%- if @arguments.any? -%>
2223

2324
arguments = <%= scope.function_icinga2_config_value([@arguments]) %>
2425
<%- end -%>
2526
<%- if @vars.any? -%>
2627

27-
vars += <%= scope.function_icinga2_config_value([@vars]) %>
28+
vars = <%= scope.function_icinga2_config_value([@vars]) %>
2829
<%- end -%>
2930
<%- if @timeout -%>
3031

3132
timeout = <%= @timeout %>
3233
<%- end -%>
3334
<%- if @env.any? -%>
3435

35-
env += <%= scope.function_icinga2_config_value([@env]) %>
36+
env = <%= scope.function_icinga2_config_value([@env]) %>
3637
<%- end -%>
3738
}

0 commit comments

Comments
 (0)