2017-02-07 01:02:03 -05:00
|
|
|
#
|
|
|
|
# Cookbook Name:: zabbix
|
|
|
|
# Recipe:: server
|
|
|
|
#
|
|
|
|
# Copyright 2017, Linux-Help.org
|
|
|
|
# Authors:
|
|
|
|
# Eric Renfro <psi-jack@linux-help.org>
|
|
|
|
#
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
include_recipe 'chef-vault'
|
|
|
|
include_recipe "#{cookbook_name}::database"
|
2017-02-07 01:02:03 -05:00
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
#################################
|
|
|
|
# Include Additional Repositories
|
|
|
|
case node['platform_family']
|
|
|
|
when 'rhel'
|
|
|
|
include_recipe 'yum-ius'
|
|
|
|
include_recipe 'yum-zabbix'
|
2017-02-07 01:02:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
#############################
|
|
|
|
# Setup and Install Webserver
|
|
|
|
case node['zabbix']['webserver']['backend']
|
|
|
|
when 'apache'
|
|
|
|
include_recipe "#{cookbook_name}::server_apache"
|
|
|
|
when 'nginx'
|
|
|
|
include_recipe "#{cookbook_name}::server_nginx"
|
|
|
|
else
|
|
|
|
Chef::Application.fatal!('Webserver backend can either be apache or nginx', 121)
|
2017-02-07 01:02:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
#######################
|
2017-02-12 15:46:48 -05:00
|
|
|
# Setup and Install PHP
|
|
|
|
include_recipe "#{cookbook_name}::server_php"
|
2017-02-07 01:02:03 -05:00
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
#######################
|
|
|
|
# Install Zabbix Server
|
|
|
|
case node['zabbix']['database']['backend']
|
|
|
|
when 'postgresql'
|
|
|
|
%w(zabbix-server-pgsql zabbix-web-pgsql zabbix-get).each do |pkg|
|
|
|
|
package pkg
|
|
|
|
end
|
|
|
|
when 'mysql', 'mariadb', 'percona'
|
|
|
|
%w(zabbix-server-mysql zabbix-web-mysql zabbix-get).each do |pkg|
|
|
|
|
package pkg
|
|
|
|
end
|
2017-02-07 01:02:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
#########################
|
|
|
|
# Configure Zabbix Server
|
2017-02-07 01:02:03 -05:00
|
|
|
template "/etc/zabbix/zabbix_server.conf" do
|
2017-02-12 15:42:59 -05:00
|
|
|
credentials = chef_vault_item("secrets", "zabbix")
|
2017-02-07 01:02:03 -05:00
|
|
|
variables({
|
2017-02-12 15:42:59 -05:00
|
|
|
:DBUsername => credentials['username'],
|
|
|
|
:DBPassword => credentials['password'],
|
|
|
|
:DBDatabase => credentials['database']
|
2017-02-07 01:02:03 -05:00
|
|
|
})
|
2017-02-12 15:42:59 -05:00
|
|
|
source %W{
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform']}-#{node['platform_version'].to_i}/zabbix_server.conf.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform']}/zabbix_server.conf.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform_family']}-#{node['platform_version'].to_i}/zabbix_server.conf.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform_family']}/zabbix_server.conf.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/zabbix_server.conf.erb
|
|
|
|
zabbix/zabbix_server.conf.erb
|
|
|
|
default/zabbix_server.conf.erb
|
|
|
|
zabbix_server.conf.erb
|
|
|
|
}
|
2017-02-07 01:02:03 -05:00
|
|
|
sensitive true
|
2017-02-12 15:42:59 -05:00
|
|
|
mode "0640"
|
2017-02-07 01:02:03 -05:00
|
|
|
owner "root"
|
|
|
|
group "root"
|
|
|
|
notifies :restart, "service[zabbix-server]", :immediately
|
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
directory "/etc/zabbix/web" do
|
|
|
|
mode "0750"
|
|
|
|
owner "root"
|
|
|
|
group case node['zabbix']['php']['use_fpm']
|
|
|
|
when true
|
|
|
|
node['php']['fpm_group']
|
|
|
|
else
|
|
|
|
case node['zabbix']['webserver']['backend']
|
|
|
|
when 'apache'
|
|
|
|
node['apache']['group']
|
|
|
|
when 'nginx'
|
2017-02-12 21:51:59 -05:00
|
|
|
node['php']['fpm_group']
|
2017-02-12 15:42:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-07 01:02:03 -05:00
|
|
|
template "/etc/zabbix/web/zabbix.conf.php" do
|
2017-02-12 15:42:59 -05:00
|
|
|
credentials = chef_vault_item("secrets", "zabbix")
|
2017-02-07 01:02:03 -05:00
|
|
|
variables({
|
2017-02-12 15:42:59 -05:00
|
|
|
:DBUsername => credentials['username'],
|
|
|
|
:DBPassword => credentials['password'],
|
|
|
|
:DBDatabase => credentials['database']
|
2017-02-07 01:02:03 -05:00
|
|
|
})
|
2017-02-12 15:42:59 -05:00
|
|
|
source %W{
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform']}-#{node['platform_version'].to_i}/zabbix.conf.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform']}/zabbix.conf.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform_family']}-#{node['platform_version'].to_i}/zabbix.conf.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform_family']}/zabbix.conf.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/zabbix.conf.php.erb
|
|
|
|
zabbix/zabbix.conf.php.erb
|
|
|
|
default/zabbix.conf.php.erb
|
|
|
|
zabbix.conf.php.erb
|
|
|
|
}
|
2017-02-07 01:02:03 -05:00
|
|
|
sensitive true
|
2017-02-12 15:42:59 -05:00
|
|
|
mode "0640"
|
2017-02-07 01:02:03 -05:00
|
|
|
owner "root"
|
2017-02-12 15:42:59 -05:00
|
|
|
group case node['zabbix']['php']['use_fpm']
|
|
|
|
when true
|
|
|
|
node['php']['fpm_group']
|
|
|
|
else
|
|
|
|
case node['zabbix']['webserver']['backend']
|
|
|
|
when 'apache'
|
|
|
|
node['apache']['group']
|
|
|
|
when 'nginx'
|
2017-02-12 21:51:59 -05:00
|
|
|
node['php']['fpm_group']
|
2017-02-12 15:42:59 -05:00
|
|
|
end
|
|
|
|
end
|
2017-02-07 01:02:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
template "/etc/zabbix/web/maintenance.inc.php" do
|
|
|
|
source %W{
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform']}-#{node['platform_version'].to_i}/maintenance.inc.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform']}/maintenance.inc.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform_family']}-#{node['platform_version'].to_i}/maintenance.inc.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/#{node['platform_family']}/maintenance.inc.php.erb
|
|
|
|
zabbix/#{node['zabbix']['version']}/maintenance.inc.php.erb
|
|
|
|
zabbix/maintenance.inc.php.erb
|
|
|
|
default/maintenance.inc.php.erb
|
|
|
|
maintenance.inc.php.erb
|
|
|
|
}
|
|
|
|
sensitive true
|
|
|
|
mode "0640"
|
2017-02-07 01:02:03 -05:00
|
|
|
owner "root"
|
2017-02-12 15:42:59 -05:00
|
|
|
group case node['zabbix']['php']['use_fpm']
|
|
|
|
when true
|
|
|
|
node['php']['fpm_group']
|
|
|
|
else
|
|
|
|
case node['zabbix']['webserver']['backend']
|
|
|
|
when 'apache'
|
|
|
|
node['apache']['group']
|
|
|
|
when 'nginx'
|
2017-02-12 21:51:59 -05:00
|
|
|
node['php']['fpm_group']
|
2017-02-12 15:42:59 -05:00
|
|
|
end
|
|
|
|
end
|
2017-02-07 01:02:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
#################
|
|
|
|
# Manage Services
|
|
|
|
service 'zabbix-server' do
|
2017-02-07 01:02:03 -05:00
|
|
|
supports :restart => true, :start => true
|
2017-02-12 15:42:59 -05:00
|
|
|
action [:enable, :start]
|
|
|
|
subscribes :restart, "template[/etc/zabbix/zabbix_server.conf]", :delayed
|
2017-02-07 01:02:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
service 'php-fpm' do
|
|
|
|
action [:enable, :start]
|
|
|
|
subscribes :reload, "php_fpm_pool[default]", :delayed
|
|
|
|
only_if { node['zabbix']['php']['use_fpm'] }
|
2017-02-07 01:02:03 -05:00
|
|
|
end
|
|
|
|
|
2017-02-12 15:42:59 -05:00
|
|
|
######################
|
|
|
|
# Include Zabbix Agent
|
2017-02-07 01:02:03 -05:00
|
|
|
include_recipe 'zabbix::agent'
|