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

Commit

Permalink
Bug #9738, enable ITL for resource eventcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
vkhatri committed Jul 28, 2015
1 parent 0ee5475 commit 057ab5e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
51 changes: 39 additions & 12 deletions providers/eventcommand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,56 @@ def object_resources
end

# collect objects and create resource template
def object_template
def objects
# collect objects
icinga2_objects = {}
icinga2_templates = {}
object_resources.reduce({}) do |_hash, resource|
next if resource.action != :create || icinga2_objects.key?(resource.name)
icinga2_objects[resource.name] = {}
icinga2_objects[resource.name] = { 'import' => resource.send('import'),
'command' => resource.send('command'),
'env' => resource.send('env'),
'timeout' => resource.send('timeout'),
'arguments' => resource.send('arguments'),
'custom_vars' => resource.send('custom_vars') }
next unless resource.action == :create
if resource.send('template') && !icinga2_templates.key?(resource.name)
icinga2_templates[resource.name] = {}
icinga2_templates[resource.name] = { 'import' => resource.send('import'),
'command' => resource.send('command'),
'env' => resource.send('env'),
'timeout' => resource.send('timeout'),
'arguments' => resource.send('arguments'),
'custom_vars' => resource.send('custom_vars'),
'object_class' => 'template' }
elsif icinga2_objects.key?(resource.name)
icinga2_objects[resource.name] = {}
icinga2_objects[resource.name] = { 'import' => resource.send('import'),
'command' => resource.send('command'),
'env' => resource.send('env'),
'timeout' => resource.send('timeout'),
'arguments' => resource.send('arguments'),
'custom_vars' => resource.send('custom_vars'),
'object_class' => 'object' }
end
end
[icinga2_objects, icinga2_templates]
end

# create object / template resource
def object_template
objs, tmpls = objects
# create object resource
ot = template ::File.join(node['icinga2']['objects_dir'], "#{::File.basename(__FILE__, '.rb')}.conf") do
ob = template ::File.join(node['icinga2']['objects_dir'], "#{::File.basename(__FILE__, '.rb')}.conf") do
source "object.#{::File.basename(__FILE__, '.rb')}.conf.erb"
cookbook 'icinga2'
owner node['icinga2']['user']
group node['icinga2']['group']
mode 0640
variables(:objects => objs)
notifies :reload, 'service[icinga2]', :delayed
end
te = template ::File.join(node['icinga2']['objects_dir'], "#{::File.basename(__FILE__, '.rb')}_template.conf") do
source "object.#{::File.basename(__FILE__, '.rb')}.conf.erb"
cookbook 'icinga2'
owner node['icinga2']['user']
group node['icinga2']['group']
mode 0640
variables(:objects => icinga2_objects)
variables(:objects => tmpls)
notifies :reload, 'service[icinga2]', :delayed
end
ot.updated?
ob.updated? || te.updated?
end
1 change: 1 addition & 0 deletions resources/eventcommand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
attribute :timeout, :kind_of => [String, Integer], :default => nil
attribute :arguments, :kind_of => Hash, :default => nil
attribute :custom_vars, :kind_of => Hash, :default => nil
attribute :template, :kind_of => [TrueClass, FalseClass], :default => false
2 changes: 1 addition & 1 deletion templates/default/object.eventcommand.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

<% @objects.sort.map do |object, options|%>
object EventCommand <%= object.inspect -%> {
<%= options['object_class'] -%> EventCommand <%= object.inspect -%> {
<% if options['import'] -%>
import <%= options['import'].inspect %>
<% end -%>
Expand Down

0 comments on commit 057ab5e

Please sign in to comment.