Skip to content

Enhance/package install method #179

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion attributes/agent.rb
Original file line number Diff line number Diff line change
@@ -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'
9 changes: 9 additions & 0 deletions attributes/agent_package_custom.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -28,3 +28,4 @@
default['zabbix']['gid'] = nil
default['zabbix']['home'] = '/opt/zabbix'
default['zabbix']['shell'] = '/bin/bash'
default['zabbix']['major_version'] = '2.2'
1 change: 0 additions & 1 deletion files/default/tests/minitest/server_source_test.rb
Original file line number Diff line number Diff line change
@@ -10,5 +10,4 @@
it 'runs as a daemon' do
service('zabbix_server').must_be_running
end

end
6 changes: 3 additions & 3 deletions libraries/chef_zabbix_api.rb
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion libraries/chef_zabbix_enumerations.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
@@ -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'
1 change: 0 additions & 1 deletion providers/graph.rb
Original file line number Diff line number Diff line change
@@ -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']
5 changes: 1 addition & 4 deletions providers/host.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion providers/trigger_dependency.rb
Original file line number Diff line number Diff line change
@@ -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

31 changes: 31 additions & 0 deletions recipes/_repos.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions recipes/agent_package_custom.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion recipes/agent_source.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions recipes/common.rb
Original file line number Diff line number Diff line change
@@ -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

5 changes: 2 additions & 3 deletions recipes/firewall.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion recipes/server_source.rb
Original file line number Diff line number Diff line change
@@ -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']
2 changes: 1 addition & 1 deletion resources/item.rb
Original file line number Diff line number Diff line change
@@ -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