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

Add support for installing server and agent via official packages #127

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
site :opscode
#source "http://api.berkshelf.com"

cookbook "postgresql", "= 3.2.0"
cookbook "yum", "< 3.0.0"
# Use this branch until https://github.com/yevgenko/cookbook-php-fpm/issues/26 is fixed.
cookbook "php-fpm", :github => "spinx/cookbook-php-fpm"
metadata
138 changes: 97 additions & 41 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
# This Vagrantfile needs the vagrant-omnbius plugin installed
# To install this, run "vagrant plugin install vagrant-omnibus"

BASE_IP = "192.168.50"
server_ip = "#{BASE_IP}.10"
agent_ip = "#{BASE_IP}.11"
src_agent_ip = "#{BASE_IP}.12"

Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |vbox|
vbox.customize ['modifyvm', :id,
Expand All @@ -12,53 +17,104 @@ Vagrant.configure("2") do |config|

config.vm.box = "Berkshelf-CentOS-6.3-x86_64-minimal"
config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box"
config.omnibus.chef_version = "11.6.2"

config.vm.hostname = "zabbix-berkshelf"
server_ip = "192.168.50.10"
config.vm.network :private_network, ip: server_ip
config.vm.define "zabbix-server", :primary => true do |machine|

machine.vm.hostname = "zabbix-server"
machine.vm.network :private_network, ip: server_ip

config.omnibus.chef_version = "11.6.2"
config.vm.provision :chef_solo do |chef|
chef.json = {
:mysql => {
:server_root_password => 'rootpass',
:server_debian_password => 'debpass',
:server_repl_password => 'replpass'
},
'postgresql' => {
'password' => {
'postgres' => 'rootpass'
}
},
'zabbix' => {
'agent' => {
'servers' => [server_ip],
'servers_active' => [server_ip]
},
'web' => {
'install_method' => 'apache',
'fqdn' => server_ip
machine.vm.provision :chef_solo do |chef|
chef.json = {
:mysql => {
:server_root_password => 'rootpass',
:server_debian_password => 'debpass',
:server_repl_password => 'replpass'
},
'server' => {
'install' => true,
'ipaddress' => server_ip
'postgresql' => {
'password' => {
'postgres' => 'rootpass'
}
},
'database' => {
#'dbport' => '5432',
#'install_method' => 'postgres',
'dbpassword' => 'password123'
'zabbix' => {
'agent' => {
'servers' => [server_ip],
'servers_active' => [server_ip],
'install_method' => 'package'
},
'web' => {
'install_method' => 'nginx',
'install_package' => true,
'fqdn' => server_ip,
'login' => 'Admin'
},
'server' => {
'install' => true,
'ipaddress' => server_ip,
'install_method' => 'package',
'version' => '2.2.1'
},
'database' => {
'dbport' => '5432',
'install_method' => 'postgres',
'dbpassword' => 'password123'
}
}
}
}

chef.add_recipe "database::mysql"
chef.add_recipe "mysql::server"
chef.add_recipe "zabbix"
chef.add_recipe "zabbix::database"
chef.add_recipe "zabbix::server"
chef.add_recipe "zabbix::web"
chef.add_recipe "zabbix::agent_registration"

#chef.log_level = :debug
chef.add_recipe "zabbix::database"
chef.add_recipe "zabbix"
chef.add_recipe "zabbix::server"
chef.add_recipe "zabbix::web"
chef.add_recipe "zabbix::agent_registration"
end
end
config.vm.define "zabbix-agent" do |machine|

machine.vm.hostname = "zabbix-agent"
machine.vm.network :private_network, ip: agent_ip

machine.vm.provision :chef_solo do |chef|
chef.json = {
'zabbix' => {
'agent' => {
'install_method' => 'package',
'servers' => [server_ip],
'servers_active' => [server_ip]
},
'web' => {
'fqdn' => server_ip,
'login' => 'Admin'
}
}
}

chef.add_recipe "zabbix"
chef.add_recipe "zabbix::agent_registration"
end
end
config.vm.define "zabbix-src-agent" do |machine|

machine.vm.hostname = "zabbix-src-agent"
machine.vm.network :private_network, ip: src_agent_ip

machine.vm.provision :chef_solo do |chef|
chef.json = {
'zabbix' => {
'agent' => {
'servers' => [server_ip],
'servers_active' => [server_ip]
},
'web' => {
'fqdn' => server_ip,
'login' => 'Admin'
}
}
}

chef.add_recipe "zabbix"
chef.add_recipe "zabbix::agent_registration"
end
end
end

8 changes: 7 additions & 1 deletion attributes/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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']['enable_remote_commands'] = true
default['zabbix']['agent']['listen_port'] = "10050"

Expand Down Expand Up @@ -40,3 +39,10 @@
default['zabbix']['agent']['debug_level'] = nil # default (3)
default['zabbix']['agent']['templates'] = []
default['zabbix']['agent']['interfaces'] = [ "zabbix_agent" ]

case node['zabbix']['agent']['install_method']
when "package"
default['zabbix']['agent']['include_dir'] = "/etc/zabbix/zabbix_agentd.d"
else
default['zabbix']['agent']['include_dir'] = ::File.join( node['zabbix']['etc_dir'] , "agent_include")
end
3 changes: 2 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
default['zabbix']['etc_dir'] = "/etc/zabbix"
end
default['zabbix']['install_dir'] = "/opt/zabbix"
default['zabbix']['web_dir'] = "/opt/zabbix/web"
default['zabbix']['external_dir'] = "/opt/zabbix/externalscripts"
default['zabbix']['alert_dir'] = "/opt/zabbix/AlertScriptsPath"
default['zabbix']['lock_dir'] = "/var/lock/subsys"
Expand All @@ -28,3 +27,5 @@
default['zabbix']['gid'] = nil
default['zabbix']['home'] = '/opt/zabbix'
default['zabbix']['shell'] = "/bin/bash"

default['zabbix']['major_version'] = '2.2'
7 changes: 6 additions & 1 deletion attributes/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
"date.timezone" => "'UTC'",
}


default['zabbix']['web']['install_package'] = false
if node['zabbix']['web']['install_package']
default['zabbix']['web_dir'] = "/usr/share/zabbix"
else
default['zabbix']['web_dir'] = "/opt/zabbix/web"
end
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
depends "database", ">= 1.3.0"
depends "mysql", ">= 1.3.0"
depends "ufw", ">= 0.6.1"
depends "yum"
depends "yum", "< 3.0.0"
depends "postgresql"
depends "php-fpm"
depends "nginx", ">= 1.0.0"
Expand Down
65 changes: 37 additions & 28 deletions providers/database_my_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ def create_new_database
:username => new_resource.root_username,
:password => new_resource.root_password
}
unless new_resource.package_install
zabbix_source "extract_zabbix_database" do
branch new_resource.branch
version new_resource.branch
source_url new_resource.source_url
code_dir new_resource.source_dir
target_dir "zabbix-#{new_resource.server_version}"
install_dir new_resource.install_dir
branch new_resource.branch
version new_resource.version

zabbix_source "extract_zabbix_database" do
branch new_resource.branch
version new_resource.branch
source_url new_resource.source_url
code_dir new_resource.source_dir
target_dir "zabbix-#{new_resource.server_version}"
install_dir new_resource.install_dir
branch new_resource.branch
version new_resource.version

action :extract_only
action :extract_only
end
end

ruby_block "set_updated" do
Expand Down Expand Up @@ -99,23 +100,31 @@ def create_new_database
dbname = new_resource.dbname
sql_command = "#{executable} #{root_username} #{root_password} #{host} #{port} #{dbname}"

zabbix_path = ::File.join(new_resource.source_dir, "zabbix-#{new_resource.server_version}")
sql_scripts = if new_resource.server_version.to_f < 2.0
Chef::Log.info "Version 1.x branch of zabbix in use"
[
["zabbix_populate_schema", ::File.join(zabbix_path, "create", "schema", "mysql.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "create", "data", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "create", "data", "images_mysql.sql")],
]
else
Chef::Log.info "Version 2.x branch of zabbix in use"
[
["zabbix_populate_schema", ::File.join(zabbix_path, "database", "mysql", "schema.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "database", "mysql", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "database", "mysql", "images.sql")],
]
end

if new_resource.package_install
sql_scripts = [
["zabbix_populate_schema", ::File.join(new_resource.sql_path, "create", "schema.sql")],
["zabbix_populate_data", ::File.join(new_resource.sql_path, "create", "data.sql")],
["zabbix_populate_image", ::File.join(new_resource.sql_path, "create", "images.sql")],
]
else
zabbix_path = ::File.join(new_resource.source_dir, "zabbix-#{new_resource.server_version}")
sql_scripts = if new_resource.server_version.to_f < 2.0
Chef::Log.info "Version 1.x branch of zabbix in use"
[
["zabbix_populate_schema", ::File.join(zabbix_path, "create", "schema", "mysql.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "create", "data", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "create", "data", "images_mysql.sql")],
]
else
Chef::Log.info "Version 2.x branch of zabbix in use"
[
["zabbix_populate_schema", ::File.join(zabbix_path, "database", "mysql", "schema.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "database", "mysql", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "database", "mysql", "images.sql")],
]
end
end

sql_scripts.each do |script_spec|
script_name = script_spec.first
script_path = script_spec.last
Expand Down
62 changes: 36 additions & 26 deletions providers/database_postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ def create_new_database
:password => new_resource.root_password
}

zabbix_source "extract_zabbix_database" do
branch new_resource.branch
version new_resource.branch
source_url new_resource.source_url
code_dir new_resource.source_dir
target_dir "zabbix-#{new_resource.server_version}"
install_dir new_resource.install_dir
branch new_resource.branch
version new_resource.version

action :extract_only
unless new_resource.package_install
zabbix_source "extract_zabbix_database" do
branch new_resource.branch
version new_resource.branch
source_url new_resource.source_url
code_dir new_resource.source_dir
target_dir "zabbix-#{new_resource.server_version}"
install_dir new_resource.install_dir
branch new_resource.branch
version new_resource.version

action :extract_only
end
end

ruby_block "set_updated" do
Expand Down Expand Up @@ -113,22 +115,30 @@ def create_new_database
dbname = new_resource.dbname
sql_command = "#{executable} #{username} #{host} #{dbname}"

zabbix_path = ::File.join(new_resource.source_dir, "zabbix-#{new_resource.server_version}")
sql_scripts = if new_resource.server_version.to_f < 2.0
Chef::Log.info "Version 1.x branch of zabbix in use"
[
["zabbix_populate_schema", ::File.join(zabbix_path, "create", "schema", "postgresql.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "create", "data", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "create", "data", "images_pgsql.sql")],
]
else
if new_resource.package_install
sql_scripts = [
["zabbix_populate_schema", ::File.join(new_resource.sql_path, "create", "schema.sql")],
["zabbix_populate_data", ::File.join(new_resource.sql_path, "create", "data.sql")],
["zabbix_populate_image", ::File.join(new_resource.sql_path, "create", "images.sql")],
]
else
zabbix_path = ::File.join(new_resource.source_dir, "zabbix-#{new_resource.server_version}")
sql_scripts = if new_resource.server_version.to_f < 2.0
Chef::Log.info "Version 1.x branch of zabbix in use"
[
["zabbix_populate_schema", ::File.join(zabbix_path, "create", "schema", "postgresql.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "create", "data", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "create", "data", "images_pgsql.sql")],
]
else
Chef::Log.info "Version 2.x branch of zabbix in use"
[
["zabbix_populate_schema", ::File.join(zabbix_path, "database", "postgresql", "schema.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "database", "postgresql", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "database", "postgresql", "images.sql")],
]
end
[
["zabbix_populate_schema", ::File.join(zabbix_path, "database", "postgresql", "schema.sql")],
["zabbix_populate_data", ::File.join(zabbix_path, "database", "postgresql", "data.sql")],
["zabbix_populate_image", ::File.join(zabbix_path, "database", "postgresql", "images.sql")],
]
end
end

sql_scripts.each do |script_spec|
script_name = script_spec.first
Expand Down
2 changes: 1 addition & 1 deletion recipes/_agent_common_directories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
mode "755"
end
recursive true
notifies :restart, "service[zabbix_agentd]"
notifies :restart, "service[zabbix-agentd]"
end
end
Loading