diff --git a/.kitchen.yml b/.kitchen.yml index 25d1b6d..e19fef2 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -8,8 +8,8 @@ driver_config: platforms: - name: ubuntu-10.04 - name: ubuntu-12.04 -- name: centos-6.4 -- name: centos-5.9 +- name: centos-6.6 +- name: centos-5.11 provisioner: name: chef_zero diff --git a/attributes/agent.rb b/attributes/agent.rb index 214f59f..dec36da 100644 --- a/attributes/agent.rb +++ b/attributes/agent.rb @@ -11,7 +11,7 @@ default['zabbix']['agent']['servers_active'] = [] default['zabbix']['agent']['hostname'] = node['fqdn'] default['zabbix']['agent']['configure_options'] = ['--with-libcurl'] -default['zabbix']['agent']['include_dir'] = ::File.join(node['zabbix']['etc_dir'] , 'agent_include') +default['zabbix']['agent']['include_dir'] = ::File.join(node['zabbix']['etc_dir'], 'agent_include') default['zabbix']['agent']['enable_remote_commands'] = true default['zabbix']['agent']['listen_port'] = '10050' default['zabbix']['agent']['timeout'] = '3' diff --git a/attributes/agent_package_custom.rb b/attributes/agent_package_custom.rb new file mode 100644 index 0000000..655dc43 --- /dev/null +++ b/attributes/agent_package_custom.rb @@ -0,0 +1,9 @@ +# +# Cookbook Name:: zabbix +# Attributes:: agent_package_custom + +default['zabbix']['agent_package_custom']['custom_repo_recipe'] = 'zabbix::_repos' +default['zabbix']['agent_package_custom']['package_name'] = 'zabbix-agent' +default['zabbix']['agent_package_custom']['package_version'] = nil +default['zabbix']['agent_package_custom']['package_action'] = 'install' +default['zabbix']['agent_package_custom']['package_options'] = nil diff --git a/attributes/default.rb b/attributes/default.rb index f235dd6..83b2ba5 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -28,3 +28,4 @@ default['zabbix']['gid'] = nil default['zabbix']['home'] = '/opt/zabbix' default['zabbix']['shell'] = '/bin/bash' +default['zabbix']['major_version'] = '2.2' diff --git a/files/default/tests/minitest/server_source_test.rb b/files/default/tests/minitest/server_source_test.rb index 16049ac..1bb1794 100644 --- a/files/default/tests/minitest/server_source_test.rb +++ b/files/default/tests/minitest/server_source_test.rb @@ -10,5 +10,4 @@ it 'runs as a daemon' do service('zabbix_server').must_be_running end - end diff --git a/libraries/chef_zabbix_api.rb b/libraries/chef_zabbix_api.rb index 0c2d486..126bb08 100644 --- a/libraries/chef_zabbix_api.rb +++ b/libraries/chef_zabbix_api.rb @@ -11,8 +11,8 @@ def initialize(options) Chef::Application.fatal! ':item_template or :host is required' end Chef::Application.fatal! ':item_key is required' if options[:item_key].to_s.empty? - Chef::Application.fatal! ':calc_function must be a Zabbix::API::GraphItemCalcFunction' unless options[:calc_function].kind_of?(GraphItemCalcFunction) - Chef::Application.fatal! ':type must be a Zabbix::API::GraphItemType' unless options[:type].kind_of?(GraphItemType) + Chef::Application.fatal! ':calc_function must be a Zabbix::API::GraphItemCalcFunction' unless options[:calc_function].is_a?(GraphItemCalcFunction) + Chef::Application.fatal! ':type must be a Zabbix::API::GraphItemType' unless options[:type].is_a?(GraphItemType) @options = options end @@ -80,7 +80,7 @@ def validate!(options) search = options[:useip] ? :ip : :dns Chef::Application.fatal!("#{search} must be set when :useip is #{options[:useip]}") unless options[search] Chef::Application.fatal!(':port is required') unless options[:port] - Chef::Application.fatal!(':type must be a Chef::Zabbix::API:HostInterfaceType') unless options[:type].kind_of?(Chef::Zabbix::API::HostInterfaceType) + Chef::Application.fatal!(':type must be a Chef::Zabbix::API:HostInterfaceType') unless options[:type].is_a?(Chef::Zabbix::API::HostInterfaceType) end def symbolize(options) diff --git a/libraries/chef_zabbix_enumerations.rb b/libraries/chef_zabbix_enumerations.rb index 24f0b6f..04b691f 100644 --- a/libraries/chef_zabbix_enumerations.rb +++ b/libraries/chef_zabbix_enumerations.rb @@ -73,7 +73,7 @@ class ItemType enum :zabbix_agent_active_check, 7 enum :zabbix_aggregate, 8 enum :web_item, 9 - enum :externali_check , 10 + enum :externali_check, 10 enum :database_monitor, 11 enum :ipmi_agent, 12 enum :ssh_agent, 13 diff --git a/metadata.rb b/metadata.rb index 95decb7..6936993 100644 --- a/metadata.rb +++ b/metadata.rb @@ -11,7 +11,7 @@ supports 'centos', '>= 5.0' supports 'oracle', '>= 5.0' supports 'windows' -depends 'apache2' , '>= 1.0.8' +depends 'apache2', '>= 1.0.8' depends 'database', '>= 1.3.0' depends 'mysql', '>= 1.3.0' depends 'ufw', '>= 0.6.1' diff --git a/providers/graph.rb b/providers/graph.rb index 8f6bc19..f36b2d5 100644 --- a/providers/graph.rb +++ b/providers/graph.rb @@ -1,6 +1,5 @@ action :create do Chef::Zabbix.with_connection(new_resource.server_connection) do |connection| - new_resource.graph_items.each do |graph_item| if graph_item[:item_template] template_id = Zabbix::API.find_template_ids(connection, graph_item[:item_template]).first['templateid'] diff --git a/providers/host.rb b/providers/host.rb index 13d27d3..6cb82fc 100644 --- a/providers/host.rb +++ b/providers/host.rb @@ -23,8 +23,7 @@ action :create do Chef::Zabbix.with_connection(new_resource.server_connection) do |connection| - - all_are_host_interfaces = new_resource.interfaces.all? { |interface| interface.kind_of?(Chef::Zabbix::API::HostInterface) } + all_are_host_interfaces = new_resource.interfaces.all? { |interface| interface.is_a?(Chef::Zabbix::API::HostInterface) } unless all_are_host_interfaces Chef::Application.fatal!(':interfaces must only contain Chef::Zabbix::API::HostInterface') end @@ -108,7 +107,6 @@ action :update do Chef::Zabbix.with_connection(new_resource.server_connection) do |connection| - get_host_request = { :method => 'host.get', :params => { @@ -179,7 +177,6 @@ } connection.query(create_interface_request) end - end new_resource.updated_by_last_action(true) end diff --git a/providers/trigger_dependency.rb b/providers/trigger_dependency.rb index 6de4211..ae8d9bd 100644 --- a/providers/trigger_dependency.rb +++ b/providers/trigger_dependency.rb @@ -48,7 +48,6 @@ else Chef::Log.info "Trigger '#{new_resource.trigger_name}' already depends on a trigger named '#{new_resource.dependency_name}'" end - end end diff --git a/recipes/_repos.rb b/recipes/_repos.rb new file mode 100644 index 0000000..15a5ed0 --- /dev/null +++ b/recipes/_repos.rb @@ -0,0 +1,31 @@ +# +# Cookbook Name:: zabbix +# Recipe:: _repos +# +# Copyright (C) 2014 Jorge Espada +# +# Apache 2.0 +# + +case node['platform'] +when 'ubuntu', 'debian' + apt_repository 'zabbix' do + uri "http://repo.zabbix.com/zabbix/#{node['zabbix']['major_version']}/#{node['platform']}" + distribution node['lsb']['codename'] + key 'http://repo.zabbix.com/zabbix-official-repo.key' + components ['main'] + end +when 'redhat', 'centos', 'scientific', 'oracle' + include_recipe 'yum::epel' + yum_key 'RPM-GPG-KEY-ZABBIX' do + url 'http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX' + action :add + end + yum_repository 'zabbix' do + repo_name 'zabbix' + description 'Zabbix' + key 'RPM-GPG-KEY-ZABBIX' + url "http://repo.zabbix.com/zabbix/#{node['zabbix']['major_version']}/rhel/$releasever/$basearch" + action :add + end +end diff --git a/recipes/agent_package_custom.rb b/recipes/agent_package_custom.rb new file mode 100644 index 0000000..ac73602 --- /dev/null +++ b/recipes/agent_package_custom.rb @@ -0,0 +1,21 @@ +# +# Cookbook Name:: zabbix +# Recipe:: agent_package +# +# Copyright (C) 2014 Jorge Espada +# +# Apache 2.0 +# + +# in case you using a wrapper or already have a recipe to install custom repos +include_recipe node['zabbix']['agent_package_custom']['custom_repo_recipe'] if node['zabbix']['agent_package_custom']['custom_repo_recipe'] + +# Install prerequisite RPM +package 'redhat-lsb' if node['platform_family'] == 'rhel' + +package 'zabbix-agent' do + package_name node['zabbix']['agent_package_custom']['package_name'] + version node['zabbix']['agent_package_custom']['package_version'] + action node['zabbix']['agent_package_custom']['package_action'] + options node['zabbix']['agent_package_custom']['package_options'] +end diff --git a/recipes/agent_source.rb b/recipes/agent_source.rb index 4030ab5..418eb56 100644 --- a/recipes/agent_source.rb +++ b/recipes/agent_source.rb @@ -28,7 +28,7 @@ # --prefix is controlled by install_dir configure_options = node['zabbix']['agent']['configure_options'].dup -configure_options = (configure_options || Array.new).delete_if do |option| +configure_options = (configure_options || []).delete_if do |option| option.match(/\s*--prefix(\s|=).+/) end node.normal['zabbix']['agent']['configure_options'] = configure_options diff --git a/recipes/common.rb b/recipes/common.rb index 79e0fe1..3d7a2ed 100644 --- a/recipes/common.rb +++ b/recipes/common.rb @@ -44,11 +44,11 @@ directory dir do owner node['zabbix']['login'] group node['zabbix']['group'] - mode '755' + mode '0750' recursive true # Only execute this if zabbix can't write to it. This handles cases of # dir being world writable (like /tmp) - not_if { ::File.world_writable?(dir) } + not_if { ::File.world_writable?(dir) || ['/var/log', '/var/run'].include?(dir) } end end diff --git a/recipes/firewall.rb b/recipes/firewall.rb index e92d3a1..ebd588c 100644 --- a/recipes/firewall.rb +++ b/recipes/firewall.rb @@ -20,7 +20,7 @@ if Chef::Config[:solo] Chef::Log.warn('This recipe uses search. Chef Solo does not support search.') else - zabbix_clients = search(:node , 'recipes:zabbix') + zabbix_clients = search(:node, 'recipes:zabbix') zabbix_clients.each do |client| # Accept connection from zabbix_server on agent @@ -44,9 +44,8 @@ if Chef::Config[:solo] Chef::Log.warn('This recipe uses search. Chef Solo does not support search.') else - zabbix_servers = search(:node , 'recipes:zabbix\:\:server') + zabbix_servers = search(:node, 'recipes:zabbix\:\:server') zabbix_servers.each do |server| - # Accept connection from zabbix_agent on server firewall_rule "zabbix_server_#{server[:fqdn]}" do port 10_050 diff --git a/recipes/server_source.rb b/recipes/server_source.rb index 0882d54..60af9b4 100644 --- a/recipes/server_source.rb +++ b/recipes/server_source.rb @@ -72,7 +72,7 @@ end configure_options = node['zabbix']['server']['configure_options'].dup -configure_options = (configure_options || Array.new).delete_if do |option| +configure_options = (configure_options || []).delete_if do |option| option.match(/\s*--prefix(\s|=).+/) end case node['zabbix']['database']['install_method'] diff --git a/resources/item.rb b/resources/item.rb index 95e509e..c0a3bb7 100644 --- a/resources/item.rb +++ b/resources/item.rb @@ -29,7 +29,7 @@ attribute :formula, :kind_of => Fixnum, :default => 1 attribute :delay_flex, :kind_of => String attribute :ipmi_sensor, :kind_of => String -attribute :data_type , :kind_of => Chef::Zabbix::API::DataType, :default => Chef::Zabbix::API::DataType.decimal +attribute :data_type, :kind_of => Chef::Zabbix::API::DataType, :default => Chef::Zabbix::API::DataType.decimal attribute :authtype, :kind_of => Chef::Zabbix::API::AuthType, :default => Chef::Zabbix::API::AuthType.password attribute :username, :kind_of => String attribute :password, :kind_of => String