Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Merge branch 'feature/merge_config_var' of git://github.com/gusrc/che…
Browse files Browse the repository at this point in the history
…f-icinga2
  • Loading branch information
vkhatri committed Jul 19, 2016
2 parents 0877ce2 + d6dccbc commit e72be99
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -967,12 +967,13 @@ Above LWRP resource will apply an icinga `Service` object to all `Hosts` with cu
import 'generic-service'
check_command 'check_snmp'
assign_where ['"areca" in host.vars.enabled_services']
merge_vars ['config']
check_interval '5m'
retry_interval '3m'
max_check_attempts 2
end

Above LWRP resource will apply an icinga `Service` object with a Service for set (also called hash or dictionary) to all `Hosts` with custom vars `host.vars.enabled_services` including 'areca'.
Above LWRP resource will apply an icinga `Service` object with a Service for set (also called hash or dictionary) to all `Hosts` with custom vars `host.vars.enabled_services` including 'areca'. It will also merge the values in `config` into the `Service` object.


**LWRP Options**
Expand Down Expand Up @@ -1007,6 +1008,7 @@ Above LWRP resource will apply an icinga `Service` object with a Service for set
- *icon_image* (optional, String) - icinga `Service` object attribute `icon_image`
- *icon_image_alt* (optional, String) - icinga `Service` object attribute `icon_image_alt`
- *custom_vars* (optional, Hash) - icinga `Service` object attribute `vars`
- *merge_vars* (optional, Array) - Merge vars from each member of a set into icinga `Service` object attribute `vars`
- *assign_where* (optional, Array) - an array of `assign where` statements
- *ignore_where* (optional, Array) - an array of `ignore where` statements

Expand Down
10 changes: 9 additions & 1 deletion libraries/resource_applyservice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ def icon_image_alt(arg = nil)
)
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,
Expand Down Expand Up @@ -259,7 +267,7 @@ def resource_properties(arg = nil)
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
Expand Down
7 changes: 6 additions & 1 deletion templates/default/object.applyservice.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down Expand Up @@ -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) -%>
Expand Down

0 comments on commit e72be99

Please sign in to comment.