[icinga-checkins] icinga.org: chef-icinga2/master: Add merge_vars attribute to applyservice and allow for multiple Service definitions for set by adding service name prefix

git at icinga.org git at icinga.org
Tue Jul 19 18:05:05 CEST 2016


Module: chef-icinga2
Branch: master
Commit: f1b3ae11c46b142678693b0fd7a6290f3b4f0ea8
URL:    https://git.icinga.org/?p=chef-icinga2.git;a=commit;h=f1b3ae11c46b142678693b0fd7a6290f3b4f0ea8

Author: Gavin Reynolds <g.reynolds at src.gla.ac.uk>
Date:   Thu Jul  7 13:52:46 2016 +0100

Add merge_vars attribute to applyservice and allow for multiple Service definitions for set by adding service name prefix

---

 libraries/resource_applyservice.rb             |   10 +++++++++-
 templates/default/object.applyservice.conf.erb |    7 ++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/libraries/resource_applyservice.rb b/libraries/resource_applyservice.rb
index 5d1b3d6..a647d59 100644
--- a/libraries/resource_applyservice.rb
+++ b/libraries/resource_applyservice.rb
@@ -214,6 +214,14 @@ class Chef
         )
       end
 
+      def merge_vars(arg = nil)
+        set_or_return(
+          :merge_vars, arg,
+          :kind_of => Array,
+          :default => nil
+        )
+      end
+
       def custom_vars(arg = nil)
         set_or_return(
           :custom_vars, arg,
@@ -259,7 +267,7 @@ class Chef
         set_or_return(
           :resource_properties, arg,
           :kind_of => Array,
-          :default => %w(import display_name host_name groups check_command max_check_attempts check_period check_interval retry_interval enable_notifications enable_active_checks enable_passive_checks enable_event_handler enable_flapping enable_perfdata event_command flapping_threshold volatile zone command_endpoint notes notes_url action_url icon_image icon_image_alt custom_vars assign_where ignore_where set)
+          :default => %w(import display_name host_name groups check_command max_check_attempts check_period check_interval retry_interval enable_notifications enable_active_checks enable_passive_checks enable_event_handler enable_flapping enable_perfdata event_command flapping_threshold volatile zone command_endpoint notes notes_url action_url icon_image icon_image_alt merge_vars custom_vars assign_where ignore_where set)
         )
       end
     end
diff --git a/templates/default/object.applyservice.conf.erb b/templates/default/object.applyservice.conf.erb
index 6b2eb7f..9200ca1 100644
--- a/templates/default/object.applyservice.conf.erb
+++ b/templates/default/object.applyservice.conf.erb
@@ -8,7 +8,7 @@
 */
 
 <% @objects.sort.map do |object, options|%>
-apply Service <%= options['set'].nil? ? object.inspect : "for (#{options['set']})" -%> {
+apply Service <%= object.inspect -%><%= " for (#{options['set']})" unless options['set'].nil? -%> {
   <%- if options['import'] -%>
   import <%= options['import'].inspect %>
   <%- end -%>
@@ -91,6 +91,11 @@ apply Service <%= options['set'].nil? ? object.inspect : "for (#{options['set']}
   ignore where <%= i %>
   <% end -%>
   <% end -%>
+  <% if options['merge_vars'] -%>
+  <% options['merge_vars'].each do |var| -%>
+  vars += <%= var %>
+  <% end -%>
+  <% end -%>
   <% if options['custom_vars'] -%>
   <% Hash[options['custom_vars'].sort].each do |var, value| -%>
   <% if var && value && value.is_a?(Hash) -%>



More information about the icinga-checkins mailing list