Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host update does not work #149

Open
odyssey4me opened this issue Mar 14, 2014 · 6 comments
Open

Host update does not work #149

odyssey4me opened this issue Mar 14, 2014 · 6 comments

Comments

@odyssey4me
Copy link

When changing the attributes for a host to update the host group or templates, the update library does not update the host's configuration.

The error:

Error executing action `create_or_update` on resource 'zabbix_host[zabbix-server.example.org]'

NoMethodError
-------------
undefined method `values' for #<Array:0x00000003d264e8>

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/zabbix/providers/host.rb:166:in `block (2 levels) in class_from_file'
/var/chef/cache/cookbooks/zabbix/libraries/zabbix_connection.rb:19:in `call'
/var/chef/cache/cookbooks/zabbix/libraries/zabbix_connection.rb:19:in `with_connection'
/var/chef/cache/cookbooks/zabbix/providers/host.rb:115:in `block in class_from_file'
/var/chef/cache/cookbooks/zabbix/providers/host.rb:18:in `block (2 levels) in class_from_file'
/var/chef/cache/cookbooks/zabbix/libraries/zabbix_connection.rb:19:in `call'
/var/chef/cache/cookbooks/zabbix/libraries/zabbix_connection.rb:19:in `with_connection'
/var/chef/cache/cookbooks/zabbix/providers/host.rb:2:in `block in class_from_file'


Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/zabbix/recipes/agent_registration.rb

 64: zabbix_host node['zabbix']['agent']['hostname'] do
 65:   create_missing_groups true
 66:   server_connection connection_info
 67:   parameters ({
 68:     :host => node['hostname'],
 69:     :groupNames => node['zabbix']['agent']['groups'],
 70:     :templates => node['zabbix']['agent']['templates'],
 71:     :interfaces => interface_data
 72:   })
 73:   action :nothing
 74: end
 75:



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/zabbix/recipes/agent_registration.rb:64:in `from_file'

zabbix_host("zabbix-server.example.org") do
  action [:nothing]
  retries 0
  retry_delay 2
  cookbook_name "zabbix"
  recipe_name "agent_registration"
  create_missing_groups true
  server_connection {:url=>"http://zabbix-server.example.org/api_jsonrpc.php", :user=>"admin", :password=>"mysecretpassword"}
  parameters {:host=>"zabbix-server", :groupNames=>["chef-agent", "Zabbix Servers"], :templates=>[], :interfaces=>[{:type=>1, :main=>1, :useip=>1, :ip=>"10.12.12.8", :dns=>"zabbix-server.example.org", :port=>"10050"}]}
  hostname "zabbix-server.example.org"
end

If I delete the host from zabbix, then re-run chef-client it works as expected.

@odyssey4me
Copy link
Author

It would appear that the offending line is this one: https://github.com/laradji/zabbix/blob/master/providers/host.rb#L161

I changed host["interfaces"].values.map to host["interfaces"].map and it appears to resolve the problem without any unwanted side-effects.

@bduong
Copy link

bduong commented May 20, 2014

+1

@mikesplain
Copy link

+1 That works for me too. This issue occurs any time I try set node['zabbix']['agent']['templates'] and @odyssey4me's solution seems to work for me.

mikesplain added a commit to mikesplain/zabbix that referenced this issue Jun 12, 2014
@laradji
Copy link
Owner

laradji commented Jun 12, 2014

tks @odyssey4me
@guilhem your the expert on this part of the cookbook :), what do you think ?

@nightw
Copy link
Contributor

nightw commented Jul 17, 2014

It also fixed the problem for me, I'm already using it. Please apply the proposed fix.

@frostyslav
Copy link

I don't know if it is just mine setup, but changing host["interfaces"].values.map to host["interfaces"].map just lead me to a new error.
Server answer API error: { "code": -32602, "message": "Invalid params.", "data": "Host cannot have more than one default interface of the same type." }
So, it tries to create the existing interface. After a little digging it appeared that it existing_interface has keys as Strings, while desired_interface has keys as Symbols.
That's why when there is a check if the interface already exists on https://github.com/laradji/zabbix/blob/master/providers/host.rb#L224, check fails.
I have fixed it by adding desired_interface = Hash[desired_interface.map{ |k, v| [k.to_s, v] }] and existing_interface = Hash[existing_interface.map{ |k, v| [k.to_s, v] }] after line 222 and line 223 respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants