Icinga / chef-icinga2

Icinga 2 Chef Cookbook
https://supermarket.chef.io/cookbooks/icinga2
Apache License 2.0
41 stars 55 forks source link

[dev.icinga.com #12843] Adding zone attribute to basically all resources is failing #234

Open icinga-migration opened 8 years ago

icinga-migration commented 8 years ago

This issue has been migrated from Redmine: https://dev.icinga.com/issues/12843

Created by rnekkanti on 2016-10-03 17:45:24 +00:00

Assignee: (none) Status: New Target Version: (none) Last Update: 2016-10-03 17:45:24 +00:00 (in Redmine)


Below is the applyservice resource definition:

icinga2_applyservice 'cluster-check' do import 'landing-page' display_name 'cluster-check' check_command 'cluster' zone 'test' assign_where ['match("opsmonitor", host.vars.tags)'] ignore_where ['match("ops-nw-monitor*", host.name)'] end

Error:

Error executing action `create` on resource 'template[zone_template_applyservice_test_cluster-check]'

NoMethodError

Cookbook Trace:

/var/chef/cache/cookbooks/icinga2/libraries/provider_instance.rb:188:in `block (3 levels) in process_icinga2_resources' /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:78:in `run_action' /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block (2 levels) in converge' /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `each' /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:106:in `block in converge' /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb:105:in `converge'

Resource Declaration:

# In /var/chef/cache/cookbooks/icinga2/libraries/provider_instance.rb

179: zoned_te = template "zone_template#{resource_name}#{zone}_#{new_resource.name}" do 180: path ::File.join(node['icinga2']['zones_dir'], zone, "#{resource_name}_template.conf") 181: source "object.#{resource_name}.conf.erb" 182: cookbook 'icinga2' 183: owner node['icinga2']['user'] 184: group node['icinga2']['group'] 185: mode 0o640 186: variables :objects => zoned_templates 187: notifies :reload, 'service[icinga2]' 188: only_if { !zoned_templates.length.empty? } 189: end 190:

Compiled Resource:

# Declared in /var/chef/cache/cookbooks/icinga2/libraries/provider_instance.rb:179:in `block in process_icinga2_resources'

template("zone_template_applyservice_test_cluster-check") do action [:create] retries 0 retry_delay 2 default_guard_interpreter :default path "/etc/icinga2/zones.d/test/applyservice_template.conf" backup 5 atomic_update true source "object.applyservice.conf.erb" cookbook "icinga2" variables {:objects=>{}} declared_type :template cookbook_name "gnops_icinga2" mode 416 owner "nagios" group "nagios" only_if { #code block } end

Running handlers: Running handlers complete Chef Client failed. 4 resources updated in 06 seconds root@ops-monitor-test-1:/etc/icinga2/zones.d/test#

When I modify the icinga cookbook provider_instance.rb file and change the zoned_objects.length.empty? to zoned_objects.empty? and zoned_templates.length.empty? to zoned_templates.empty? in line 175 and 189 we are not seeing the error. Below is the modified code. We did a for the zoned_objects.length and is returning 1. Below is the put.

zoned_ot = template "zone_config#{resource_name}#{zone}_#{new_resource.name}" do path ::File.join(node['icinga2']['zones_dir'], zone, "#{resource_name}.conf") source "object.#{resource_name}.conf.erb" cookbook 'icinga2' owner node['icinga2']['user'] group node['icinga2']['group'] mode 0640 variables :objects => zoned_objects notifies :reload, 'service[icinga2]' only_if { !zoned_objects.empty? } end puts 'zone length' puts zoned_objects.length zoned_te = template "zone_template#{resource_name}#{zone}_#{new_resource.name}" do path ::File.join(node['icinga2']['zones_dir'], zone, "#{resource_name}_template.conf") source "object.#{resource_name}.conf.erb" cookbook 'icinga2' owner node['icinga2']['user'] group node['icinga2']['group'] mode 0o640 variables :objects => zoned_templates notifies :reload, 'service[icinga2]' only_if { !zoned_templates.empty? } end

zone length 1 (up to date)

rnekkanti commented 7 years ago

@vkhatri any update on this. I am seeing the same issue on the newest version of the cookbook as well.

tonnenpinguin commented 7 years ago

Same here!

vkhatri commented 7 years ago

checking, will update shortly.

vkhatri commented 7 years ago

@tonnenpinguin 👍 Thank you for the PR.

tonnenpinguin commented 7 years ago

I think this can be closed, right?