Skip to content

Commit

Permalink
Add Zabbix 6.0 support
Browse files Browse the repository at this point in the history
Signed-off-by: Christos Papageorgiou <[email protected]>
  • Loading branch information
root-expert committed Mar 17, 2022
1 parent cea4958 commit 6aa8225
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ Take a look at the [REFERENCE.md](https://github.com/voxpupuli/puppet-zabbix/blo

## Limitations

This module supports Zabbix 4.0, 5.0, 5.2 and 5.4. The upstream supported versions are documented [here](https://www.zabbix.com/de/life_cycle_and_release_policy)
This module supports Zabbix 4.0, 5.0, 5.2, 5.4 and 6.0. The upstream supported versions are documented [here](https://www.zabbix.com/de/life_cycle_and_release_policy)
Please have a look into the metadata.json for all supported operating systems.

This module is supported on both the community and the Enterprise version of Puppet.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/zabbix_template/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create
updateExisting: true
},
# templateDashboards was renamed to templateScreen on Zabbix >= 5.2
(@resource[:zabbix_version] =~ %r{5\.[24]} ? :templateDashboards : :templateScreens) => {
(@resource[:zabbix_version] =~ %r{5\.[24]|6\.0} ? :templateDashboards : :templateScreens) => {
createMissing: true,
deleteMissing: (@resource[:delete_missing_templatescreens].nil? ? false : @resource[:delete_missing_templatescreens]),
updateExisting: true
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/zabbix_template_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Puppet::Type.newtype(:zabbix_template_host) do
@doc = <<-DOC
Link or Unlink template to host.
Link or Unlink template to host. Only for Zabbix < 6.0!
Example.
Name should be in the format of "template_name@hostname"
Expand Down
12 changes: 9 additions & 3 deletions manifests/database/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
assert_private()

if ($database_schema_path == false) or ($database_schema_path == '') {
if versioncmp($zabbix_version, '5.4') == 0 {
if versioncmp($zabbix_version, '5.4') >= 0 {
$schema_path = '/usr/share/doc/zabbix-sql-scripts/mysql/'
} else {
$schema_path = '/usr/share/doc/zabbix-*-mysql*'
Expand All @@ -42,10 +42,16 @@

case $zabbix_type {
'proxy': {
$zabbix_proxy_create_sql = "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < schema.sql && touch /etc/zabbix/.schema.done"
$zabbix_proxy_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? {
true => "cd ${schema_path} && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < proxy.sql && touch /etc/zabbix/.schema.done",
false => "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < schema.sql && touch /etc/zabbix/.schema.done"
}
}
default: {
$zabbix_server_create_sql = "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < create.sql && touch /etc/zabbix/.schema.done"
$zabbix_server_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? {
true => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < server.sql && touch /etc/zabbix/.schema.done",
false => "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < create.sql && touch /etc/zabbix/.schema.done"
}
$zabbix_server_images_sql = 'touch /etc/zabbix/.images.done'
$zabbix_server_data_sql = 'touch /etc/zabbix/.data.done'
}
Expand Down
14 changes: 10 additions & 4 deletions manifests/database/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

if ($database_schema_path == false) or ($database_schema_path == '') {
if member(['CentOS', 'RedHat', 'OracleLinux', 'VirtuozzoLinux'], $facts['os']['name']) {
if versioncmp($zabbix_version, '5.4') == 0 {
if versioncmp($zabbix_version, '5.4') >= 0 {
$schema_path = '/usr/share/doc/zabbix-sql-scripts/postgresql/'
} else {
$schema_path = "/usr/share/doc/zabbix-*-pgsql-${zabbix_version}*/"
}
} else {
if versioncmp($zabbix_version, '5.4') == 0 {
if versioncmp($zabbix_version, '5.4') >= 0 {
$schema_path = '/usr/share/doc/zabbix-sql-scripts/postgresql/'
} else {
$schema_path = '/usr/share/doc/zabbix-*-pgsql'
Expand All @@ -49,10 +49,16 @@

case $zabbix_type {
'proxy': {
$zabbix_proxy_create_sql = "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
$zabbix_proxy_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? {
true => "cd ${schema_path} && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f proxy.sql && touch /etc/zabbix/.schema.done",
false => "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
}
}
default: {
$zabbix_server_create_sql = "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f create.sql && touch /etc/zabbix/.schema.done"
$zabbix_server_create_sql = versioncmp($zabbix_version, '6.0') >= 0 ? {
true => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f server.sql && touch /etc/zabbix/.schema.done",
false => "cd ${schema_path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' ${port}-d '${database_name}' -f create.sql && touch /etc/zabbix/.schema.done"
}
$zabbix_server_images_sql = 'touch /etc/zabbix/.images.done'
$zabbix_server_data_sql = 'touch /etc/zabbix/.data.done'
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/proxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
}

if $manage_database {
if versioncmp($zabbix_version, '5.4') == 0 {
if versioncmp($zabbix_version, '5.4') >= 0 {
package { 'zabbix-sql-scripts':
ensure => present,
require => Class['zabbix::repo'],
Expand All @@ -364,7 +364,7 @@
}

# Zabbix version 5.4 uses zabbix-sql-scripts for initializing the database.
if versioncmp($zabbix_version, '5.4') == 0 {
if versioncmp($zabbix_version, '5.4') >= 0 {
$zabbix_database_require = [Package["zabbix-proxy-${db}"], Package['zabbix-sql-scripts']]
} else {
$zabbix_database_require = Package["zabbix-proxy-${db}"]
Expand Down
12 changes: 6 additions & 6 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
Optional[Stdlib::Absolutepath] $socketdir = $zabbix::params::server_socketdir,
Optional[Stdlib::HTTPUrl] $webserviceurl = undef,
) inherits zabbix::params {
# zabbix server 5.2 and 5.4 is not supported on RHEL 7.
# zabbix server 5.2, 5.4 and 6.0 is not supported on RHEL 7.
# https://www.zabbix.com/documentation/current/manual/installation/install_from_packages/rhel_centos
if $facts['os']['family'] == 'RedHat' and versioncmp($zabbix_version, '5.2') >= 0 {
if versioncmp($facts['os']['release']['major'], '7') == 0 {
Expand All @@ -295,7 +295,7 @@
}
}

if versioncmp($zabbix_version, '5.4') == 0 {
if versioncmp($zabbix_version, '5.4') >= 0 {
package { 'zabbix-sql-scripts':
ensure => present,
require => Class['zabbix::repo'],
Expand All @@ -309,8 +309,8 @@
'postgresql' : {
$db = 'pgsql'

# Zabbix version 5.4 uses zabbix-sql-scripts for initializing the database.
if versioncmp($zabbix_version, '5.4') == 0 {
# Zabbix version >= 5.4 uses zabbix-sql-scripts for initializing the database.
if versioncmp($zabbix_version, '5.4') >= 0 {
$zabbix_database_require = [Package["zabbix-server-${db}"], Package['zabbix-sql-scripts']]
} else {
$zabbix_database_require = Package["zabbix-server-${db}"]
Expand All @@ -335,8 +335,8 @@
'mysql' : {
$db = 'mysql'

# Zabbix version 5.4 uses zabbix-sql-scripts for initializing the database.
if versioncmp($zabbix_version, '5.4') == 0 {
# Zabbix version >= 5.4 uses zabbix-sql-scripts for initializing the database.
if versioncmp($zabbix_version, '5.4') >= 0 {
$zabbix_database_require = [Package["zabbix-server-${db}"], Package['zabbix-sql-scripts']]
} else {
$zabbix_database_require = Package["zabbix-server-${db}"]
Expand Down
2 changes: 1 addition & 1 deletion manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
'4.0': {
$zabbixapi_version = '4.2.0'
}
/^5\.[024]/: {
/^[56]\.[024]/: {
$zabbixapi_version = '5.0.0-alpha1'
}
default: {
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/zabbix_application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# 5.2 and 5.4 server packages are not available for RHEL 7
next if zabbix_version == '5.2' && default[:platform] == 'el-7-x86_64'
# Application API was removed in Zabbix 5.4
next if zabbix_version == '5.4'
next if zabbix_version >= '5.4'
# No Zabbix 5.2 packages on Debian 11
next if zabbix_version == '5.2' && default[:platform] == 'debian-11-amd64'

Expand Down
5 changes: 2 additions & 3 deletions spec/acceptance/zabbix_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
# rubocop:disable RSpec/LetBeforeExamples
describe 'zabbix_host type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
supported_versions.each do |zabbix_version|
# 5.2 and 5.4 server packages are not available for RHEL 7
next if zabbix_version == '5.2' && default[:platform] == 'el-7-x86_64'
next if zabbix_version == '5.4' && default[:platform] == 'el-7-x86_64'
# >= 5.2 server packages are not available for RHEL 7
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
# No Zabbix 5.2 packages on Debian 11
next if zabbix_version == '5.2' && default[:platform] == 'debian-11-amd64'

Expand Down
5 changes: 2 additions & 3 deletions spec/acceptance/zabbix_hostgroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

describe 'zabbix_hostgroup type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
supported_versions.each do |zabbix_version|
# 5.2 and 5.4 server packages are not available for RHEL 7
next if zabbix_version == '5.2' && default[:platform] == 'el-7-x86_64'
next if zabbix_version == '5.4' && default[:platform] == 'el-7-x86_64'
# >= 5.2 server packages are not available for RHEL 7
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
# No Zabbix 5.2 packages on Debian 11
next if zabbix_version == '5.2' && default[:platform] == 'debian-11-amd64'

Expand Down
5 changes: 2 additions & 3 deletions spec/acceptance/zabbix_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
# rubocop:disable RSpec/LetBeforeExamples
describe 'zabbix_proxy type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
supported_versions.each do |zabbix_version|
# 5.2 and 5.4 server packages are not available for RHEL 7
next if zabbix_version == '5.2' && default[:platform] == 'el-7-x86_64'
next if zabbix_version == '5.4' && default[:platform] == 'el-7-x86_64'
# >= 5.2 server packages are not available for RHEL 7
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
# No Zabbix 5.2 packages on Debian 11
next if zabbix_version == '5.2' && default[:platform] == 'debian-11-amd64'

Expand Down
7 changes: 4 additions & 3 deletions spec/acceptance/zabbix_template_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

describe 'zabbix_template_host type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
supported_versions.each do |zabbix_version|
# 5.2 and 5.4 server packages are not available for RHEL 7
next if zabbix_version == '5.2' && default[:platform] == 'el-7-x86_64'
next if zabbix_version == '5.4' && default[:platform] == 'el-7-x86_64'
# Zabbix 6.0 removed the ability to attach templates directly to hosts.
next if zabbix_version == '6.0'
# >= 5.2 server packages are not available for RHEL 7
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
# No Zabbix 5.2 packages on Debian 11
next if zabbix_version == '5.2' && default[:platform] == 'debian-11-amd64'

Expand Down
5 changes: 2 additions & 3 deletions spec/acceptance/zabbix_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

describe 'zabbix_template type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
supported_versions.each do |zabbix_version|
# 5.2 and 5.4 server packages are not available for RHEL 7
next if zabbix_version == '5.2' && default[:platform] == 'el-7-x86_64'
next if zabbix_version == '5.4' && default[:platform] == 'el-7-x86_64'
# >= 5.2 server packages are not available for RHEL 7
next if zabbix_version >= '5.2' && default[:platform] == 'el-7-x86_64'
# No Zabbix 5.2 packages on Debian 11
next if zabbix_version == '5.2' && default[:platform] == 'debian-11-amd64'

Expand Down
29 changes: 23 additions & 6 deletions spec/classes/database_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@

supported_versions.each do |zabbix_version|
# path to sql files on Debian and RedHat
path = if zabbix_version == '5.4'
path = if Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
'/usr/share/doc/zabbix-sql-scripts/mysql/'
else
'/usr/share/doc/zabbix-*-mysql*'
end

sql_server = case zabbix_version
when '6.0'
'server.sql'
else
'create.sql'
end

context "when zabbix_type is server and zabbix version is #{zabbix_version}" do
describe 'and database_port is defined' do
let :params do
Expand All @@ -49,7 +56,7 @@

it { is_expected.to contain_class('zabbix::database::mysql') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -P 3306 -D 'zabbix-server' < create.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f #{sql_server}.gz ]; then gunzip -f #{sql_server}.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -P 3306 -D 'zabbix-server' < #{sql_server} && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
end
Expand All @@ -68,13 +75,13 @@

it { is_expected.to contain_class('zabbix::database::mysql') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path} && if [ -f #{sql_server}.gz ]; then gunzip -f #{sql_server}.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < #{sql_server} && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { is_expected.to contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
end
end

context "when zabbix_type is server and zabbix version is #{zabbix_version}" do
context "when zabbix_type is proxy and zabbix version is #{zabbix_version}" do
describe 'and database_port is defined' do
let :params do
{
Expand All @@ -90,7 +97,12 @@

it { is_expected.to contain_class('zabbix::database::mysql') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -P 3306 -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }

if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') < 0
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -P 3306 -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
else
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -P 3306 -D 'zabbix-proxy' < proxy.sql && touch /etc/zabbix/.schema.done") }
end
end

describe 'and no database_port is defined' do
Expand All @@ -107,7 +119,12 @@

it { is_expected.to contain_class('zabbix::database::mysql') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }

if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') < 0
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && if [ -f schema.sql.gz ]; then gunzip -f schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
else
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < proxy.sql && touch /etc/zabbix/.schema.done") }
end
end
end
end
Expand Down
Loading

0 comments on commit 6aa8225

Please sign in to comment.