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 Zabbix 5.4 support #776

Merged
merged 5 commits into from
Aug 4, 2021
Merged
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
1 change: 1 addition & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Gemfile:
- gem: 'zabbixapi'
spec/spec_helper.rb:
mock_with: ':mocha'
spec_overrides: "require 'support/acceptance/supported_versions'"
spec/spec_helper_acceptance.rb:
unmanaged: false
.github/workflows/ci.yml:
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/provider/zabbix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def self.create_connection
user: api_config['default']['zabbix_user'],
password: api_config['default']['zabbix_pass'],
http_user: api_config['default']['zabbix_user'],
http_password: api_config['default']['zabbix_pass']
http_password: api_config['default']['zabbix_pass'],
ignore_version: true
)
zbx
end
Expand Down
11 changes: 7 additions & 4 deletions lib/puppet/provider/zabbix_template/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def create
zbx.configurations.import(
format: 'xml',
rules: {
applications: {
# application parameter was removed on Zabbix 5.4
(@resource[:zabbix_version] =~ %r{[45]\.[02]} ? :applications : nil) => {
createMissing: true
},
discoveryRules: {
Expand All @@ -32,7 +33,8 @@ def create
createMissing: true,
updateExisting: true
},
screens: {
# screens parameter was removed on Zabbix 5.4
(@resource[:zabbix_version] =~ %r{[45]\.[02]} ? :screens : nil) => {
createMissing: true,
updateExisting: true
},
Expand All @@ -43,15 +45,16 @@ def create
createMissing: true,
updateExisting: true
},
(@resource[:zabbix_version] =~ %r{5\.[^0]} ? :templateDashboards : :templateScreens) => {
# templateDashboards was renamed to templateScreen on Zabbix >= 5.2
(@resource[:zabbix_version] =~ %r{5\.[24]} ? :templateDashboards : :templateScreens) => {
createMissing: true,
updateExisting: true
},
triggers: {
createMissing: true,
updateExisting: true
}
},
}.delete_if { |key, _| key.nil? },
source: template_contents
)
end
Expand Down
6 changes: 5 additions & 1 deletion manifests/database/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
assert_private()

if ($database_schema_path == false) or ($database_schema_path == '') {
$schema_path = '/usr/share/doc/zabbix-*-mysql*'
if versioncmp($zabbix_version, '5.4') == 0 {
$schema_path = '/usr/share/doc/zabbix-sql-scripts/mysql/'
} else {
$schema_path = '/usr/share/doc/zabbix-*-mysql*'
}
}
else {
$schema_path = $database_schema_path
Expand Down
15 changes: 10 additions & 5 deletions manifests/database/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@
assert_private()

if ($database_schema_path == false) or ($database_schema_path == '') {
case $facts['os']['name'] {
'CentOS', 'RedHat', 'OracleLinux', 'VirtuozzoLinux': {
$schema_path = "/usr/share/doc/zabbix-*-pgsql-${zabbix_version}*/"
if member(['CentOS', 'RedHat', 'OracleLinux', 'VirtuozzoLinux'], $facts['os']['name']) {
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}*/"
}
default : {
$schema_path = '/usr/share/doc/zabbix-*-pgsql'
} else {
if versioncmp($zabbix_version, '5.4') == 0 {
$schema_path = '/usr/share/doc/zabbix-sql-scripts/postgresql/'
} else {
$schema_path = '/usr/share/doc/zabbix-*-pgsql'
}
}
} else {
Expand Down
19 changes: 17 additions & 2 deletions manifests/proxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,21 @@
}

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

# Zabbix version 5.4 uses zabbix-sql-scripts for initializing the database.
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}"]
}

case $database_type {
'postgresql' : {
# Execute the postgresql scripts
Expand All @@ -530,7 +545,7 @@
database_host => $database_host,
database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-proxy-${db}"],
require => $zabbix_database_require,
}
}
'mysql' : {
Expand All @@ -545,7 +560,7 @@
database_host => $database_host,
database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-proxy-${db}"],
require => $zabbix_database_require,
}
}

Expand Down
35 changes: 28 additions & 7 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@
Boolean $manage_startup_script = $zabbix::params::manage_startup_script,
Optional[Stdlib::Absolutepath] $socketdir = $zabbix::params::server_socketdir,
) inherits zabbix::params {
# zabbix server 5.2 is not supported on RHEL 7.
# zabbix server 5.2 and 5.4 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 $facts['os']['family'] == 'RedHat' and versioncmp($zabbix_version, '5.2') >= 0 {
if versioncmp($facts['os']['release']['major'], '7') == 0 {
fail("${facts['os']['family']} ${$facts['os']['release']['major']} is not supported for zabbix::server (yet)")
fail("${facts['os']['family']} ${$facts['os']['release']['major']} is not supported for zabbix::server (version ${$zabbix_version}) (yet)")
}
}

Expand All @@ -461,13 +461,27 @@
}
}

if versioncmp($zabbix_version, '5.4') == 0 {
package { 'zabbix-sql-scripts':
ensure => present,
require => Class['zabbix::repo'],
tag => 'zabbix',
}
}

# Get the correct database_type. We need this for installing the
# correct package and loading the sql files.

case $database_type {
'postgresql' : {
$db = 'pgsql'

# 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}"]
}

if $manage_database {
# Execute the postgresql scripts
class { 'zabbix::database::postgresql':
Expand All @@ -480,13 +494,20 @@
database_host => $database_host,
database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-server-${db}"],
require => $zabbix_database_require,
}
}
}
'mysql' : {
'mysql' : {
$db = 'mysql'

# 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}"]
}

if $manage_database {
# Execute the mysql scripts
class { 'zabbix::database::mysql':
Expand All @@ -499,7 +520,7 @@
database_host => $database_host,
database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-server-${db}"],
require => $zabbix_database_require,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
'4.0': {
$zabbixapi_version = '4.2.0'
}
/^5\.[02]/: {
/^5\.[024]/: {
$zabbixapi_version = '5.0.0-alpha1'
}
default: {
Expand Down Expand Up @@ -366,7 +366,7 @@
}
'CentOS', 'RedHat': {
$zabbix_web_package = 'zabbix-web'
if ($facts['os']['release']['major'] == '7' and versioncmp($zabbix_version, '5') >= 0) {
if ($facts['os']['release']['major'] == '7' and versioncmp($zabbix_version, '5.0') >= 0) {
package { 'zabbix-required-scl-repo':
ensure => 'latest',
name => 'centos-release-scl',
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/agent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper_acceptance'

['4.0', '5.0', '5.2'].each do |version|
supported_versions.each do |version|
describe "zabbix::agent class with zabbix_version #{version}" do
it 'works idempotently with no errors' do
pp = <<-EOS
Expand Down
1 change: 0 additions & 1 deletion spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper_acceptance'

describe 'zabbix::server class' do
context 'default parameters' do
# Using puppet_apply as a helper
Expand Down
7 changes: 5 additions & 2 deletions spec/acceptance/zabbix_application_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_application type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
%w[4.0 5.0 5.2].each do |zabbix_version|
# 5.2 server packages are not available for RHEL 7
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'
# Application API was removed in Zabbix 5.4
next if zabbix_version == '5.4'

template = case zabbix_version
when '4.0'
Expand Down
5 changes: 3 additions & 2 deletions spec/acceptance/zabbix_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

# rubocop:disable RSpec/LetBeforeExamples
describe 'zabbix_host type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
%w[4.0 5.0 5.2].each do |zabbix_version|
# 5.2 server packages are not available for RHEL 7
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'
context "create zabbix_host resources with zabbix version #{zabbix_version}" do
# This will deploy a running Zabbix setup (server, web, db) which we can
# use for custom type tests
Expand Down
6 changes: 4 additions & 2 deletions spec/acceptance/zabbix_hostgroup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_hostgroup type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
%w[4.0 5.0 5.2].each do |zabbix_version|
# 5.2 server packages are not available for RHEL 7
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'
context "create zabbix_hostgroup resources with zabbix version #{zabbix_version}" do
# This will deploy a running Zabbix setup (server, web, db) which we can
# use for custom type tests
Expand Down
5 changes: 3 additions & 2 deletions spec/acceptance/zabbix_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

# rubocop:disable RSpec/LetBeforeExamples
describe 'zabbix_proxy type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
%w[4.0 5.0 5.2].each do |zabbix_version|
# 5.2 server packages are not available for RHEL 7
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'
context "create zabbix_proxy resources with zabbix version #{zabbix_version}" do
# This will deploy a running Zabbix setup (server, web, db) which we can
# use for custom type tests
Expand Down
6 changes: 4 additions & 2 deletions spec/acceptance/zabbix_template_host_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_template_host type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
%w[4.0 5.0 5.2].each do |zabbix_version|
# 5.2 server packages are not available for RHEL 7
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'
context "create zabbix_template_host resources with zabbix version #{zabbix_version}" do
template = case zabbix_version
when '4.0'
Expand Down
13 changes: 10 additions & 3 deletions spec/acceptance/zabbix_template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'spec_helper_acceptance'
require 'serverspec_type_zabbixapi'

describe 'zabbix_template type', unless: default[:platform] =~ %r{(ubuntu-16.04|debian-9)-amd64} do
%w[4.0 5.0 5.2].each do |zabbix_version|
# 5.2 server packages are not available for RHEL 7
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'
context "create zabbix_template resources with zabbix version #{zabbix_version}" do
# This will deploy a running Zabbix setup (server, web, db) which we can
# use for custom type tests
Expand Down Expand Up @@ -57,7 +59,12 @@ class { 'zabbix':
end

let(:result_templates) do
zabbixapi('localhost', 'Admin', 'zabbix', 'template.get', selectApplications: ['name'], output: ['host']).result
# selectApplications parameter was removed in Zabbix 5.4
if zabbix_version =~ %r{5\.[^4]}
zabbixapi('localhost', 'Admin', 'zabbix', 'template.get', selectApplications: ['name'], output: ['host']).result
else
zabbixapi('localhost', 'Admin', 'zabbix', 'template.get', output: ['host']).result
end
end

context 'TestTemplate1' do
Expand Down
11 changes: 8 additions & 3 deletions spec/classes/database_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
is_expected.not_to compile.with_all_deps
end
end
# path to sql files on zabbix 3.X on Debian and RedHat
path = '/usr/share/doc/zabbix-*-mysql*'

%w[4.0 5.0 5.2].each do |zabbix_version|
supported_versions.each do |zabbix_version|
# path to sql files on Debian and RedHat
path = if zabbix_version == '5.4'
'/usr/share/doc/zabbix-sql-scripts/mysql/'
else
'/usr/share/doc/zabbix-*-mysql*'
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 Down
Loading