From 337e1d2f0ab3a408f568faf7b76c4f8f94c9ffe6 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Wed, 31 May 2017 14:12:11 +0100 Subject: [PATCH 1/2] Remove weird host.rb.good file I have no idea how this ended up here but it's not used. --- providers/host.rb.good | 116 ----------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 providers/host.rb.good diff --git a/providers/host.rb.good b/providers/host.rb.good deleted file mode 100644 index d57f61f..0000000 --- a/providers/host.rb.good +++ /dev/null @@ -1,116 +0,0 @@ -action :create_or_update do - chef_gem "zabbixapi" do - action :install - version "~> 0.6.3" - end - - require 'zabbixapi' - - - Chef::Zabbix.with_connection(new_resource.server_connection) do |connection| - - hostId = connection.query( :method => "host.get", - :params => - { - :filter => - { - :host => new_resource.hostname - } - }) - if hostId.size == 0 - action :create - else - puts "doing an update" - action :update - end - end -end - -action :create do - - chef_gem "zabbixapi" do - action :install - version "~> 0.6.3" - end - - require 'zabbixapi' - - - Chef::Zabbix.with_connection(new_resource.server_connection) do |connection| - - connection.query( :method => "host.create", - :params => { - :host => new_resource.hostname, - :interfaces => [ - { - :type => 1, - :main => 1, - :useip => 1, - :ip => node['ipaddress'], - :dns => node['fqdn'], - :port => "10050", - } - ] - } - ) - end - new_resource.updated_by_last_action(true) -end - -action :update do - chef_gem "zabbixapi" do - action :install - version "~> 0.6.3" - end - - require 'zabbixapi' - - puts node['ipaddress'] - - Chef::Zabbix.with_connection(new_resource.server_connection) do |connection| - # Update the host - connection.query( :method => "host.update", - :params => new_resource.params - ) - end - new_resource.updated_by_last_action(true) -end - -action :link do - chef_gem "zabbixapi" do - action :install - version "~> 0.6.3" - end - - require 'zabbixapi' - - puts node['ipaddress'] - - Chef::Zabbix.with_connection(new_resource.server_connection) do |connection| - puts new_resource.hostname - hostId = connection.query( :method => "host.get", - :params => { - :filter => {:host => new_resource.hostname} - }) - puts hostId - # get the IDS of the templates in the array - templateId = [] - linkTo = [] - new_resource.templates.each do |template| - puts template - templateId = connection.query( :method => "template.get", - :params => { - :filter => { - :host => template,}, - }) - puts templateId[0]['templateid'] - linkTo.push( :templateid => templateId[0]['templateid'] ) - end - connection.query( :method => "host.update", - :params => { - :hostid => hostId[0]['hostid'], - :templates => linkTo, - }) - end - new_resource.updated_by_last_action(true) -end From 2d5d5481d90177432e7ec1c41dcf34907587145a Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Wed, 31 May 2017 14:23:32 +0100 Subject: [PATCH 2/2] Determine the zabbixapi gem version automatically This doesn't change the fact that zabbixapi versions older than 3.0.0 do not work against Chef versions older than 12.15.9 due to the json gem version conflicting. I have pushed a revised version of zabbixapi 2.2.2 that allows json 2.x to my packagecloud repository. You are free to use this and I can create other versions on request. https://packagecloud.io/chewi/zabbix --- recipes/_providers_common.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/recipes/_providers_common.rb b/recipes/_providers_common.rb index 9c05f07..314ab22 100644 --- a/recipes/_providers_common.rb +++ b/recipes/_providers_common.rb @@ -1,4 +1,13 @@ chef_gem 'zabbixapi' do action :install - version '~> 0.6.3' + server_version = node['zabbix']['server']['version'].scan(/^\d+\.\d+/).first + + case server_version + when '1.8' + version '~> 0.6.3' + when '2.0', '2.2', '2.4', '3.0' + version "~> #{server_version}.0" + when '3.2' + version '~> 3.0.0' + end end