Skip to content

Commit

Permalink
Merge pull request #1 from voxpupuli/master
Browse files Browse the repository at this point in the history
rebase on current master
  • Loading branch information
ikcalB authored Dec 7, 2022
2 parents e6b031f + 5c624b8 commit 4e069f9
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 29 deletions.
4 changes: 3 additions & 1 deletion manifests/database/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
assert_private()

if ($database_schema_path == false) or ($database_schema_path == '') {
if versioncmp($zabbix_version, '5.4') >= 0 {
if versioncmp($zabbix_version, '6.0') >= 0 {
$schema_path = '/usr/share/zabbix-sql-scripts/mysql/'
} elsif versioncmp($zabbix_version, '5.4') >= 0 {
$schema_path = '/usr/share/doc/zabbix-sql-scripts/mysql/'
} else {
$schema_path = '/usr/share/doc/zabbix-*-mysql*'
Expand Down
28 changes: 13 additions & 15 deletions manifests/database/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@
$database_user = '',
$database_password = '',
$database_host = '',
Optional[Stdlib::Port::Unprivileged] $database_port = undef,
Stdlib::Port::Unprivileged $database_port = 5432,
$database_path = $zabbix::params::database_path,
) inherits zabbix::params {
assert_private()

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, '6.0') >= 0 {
$schema_path = '/usr/share/zabbix-sql-scripts/postgresql/'
} elsif 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, '6.0') >= 0 {
$schema_path = '/usr/share/zabbix-sql-scripts/postgresql/'
} elsif 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 @@ -41,33 +45,27 @@
$schema_path = $database_schema_path
}

if $database_port != undef {
$port = "-p ${database_port} "
} else {
$port = ''
}

case $zabbix_type {
'proxy': {
$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"
true => "cd ${schema_path} && psql -h '${database_host}' -U '${database_user}' -p ${database_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}' -p ${database_port} -d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
}
}
default: {
$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"
true => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -p ${database_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}' -p ${database_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'
}
}

exec { 'update_pgpass':
command => "echo ${database_host}:5432:${database_name}:${database_user}:${database_password} >> /root/.pgpass",
command => "echo ${database_host}:${database_port}:${database_name}:${database_user}:${database_password} >> /root/.pgpass",
path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
unless => "grep \"${database_host}:5432:${database_name}:${database_user}:${database_password}\" /root/.pgpass",
unless => "grep \"${database_host}:${database_port}:${database_name}:${database_user}:${database_password}\" /root/.pgpass",
require => File['/root/.pgpass'],
}

Expand Down
11 changes: 6 additions & 5 deletions manifests/web.pp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
# Is set to true, it will create the apache vhost.
if $manage_vhost {
include apache
include apache::mod::dir
if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'], '7') >= 0 and versioncmp($zabbix_version, '5') >= 0 {
if versioncmp($facts['os']['release']['major'], '7') == 0 {
$fpm_service = 'rh-php72-php-fpm'
Expand Down Expand Up @@ -407,25 +408,25 @@
add_listen => true,
directories => [
merge(
merge( {
merge({
path => '/usr/share/zabbix',
provider => 'directory',
}, $directory_allow),
$fcgi_filematch
),
merge( {
merge({
path => '/usr/share/zabbix/conf',
provider => 'directory',
}, $directory_deny),
merge( {
merge({
path => '/usr/share/zabbix/api',
provider => 'directory',
}, $directory_deny),
merge( {
merge({
path => '/usr/share/zabbix/include',
provider => 'directory',
}, $directory_deny),
merge( {
merge({
path => '/usr/share/zabbix/include/classes',
provider => 'directory',
}, $directory_deny),
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": [
{
"name": "puppetlabs/postgresql",
"version_requirement": ">= 6.4.0 < 8.0.0"
"version_requirement": ">= 6.4.0 < 9.0.0"
},
{
"name": "puppetlabs/stdlib",
Expand Down
4 changes: 3 additions & 1 deletion spec/acceptance/zabbix_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
['Template OS Linux SNMPv2']
when '5.0'
['Template OS Linux SNMP']
else
when '5.2', '5.4'
['Linux SNMP']
else
['Linux by SNMP']
end

pp1 = <<-EOS
Expand Down
4 changes: 3 additions & 1 deletion spec/classes/database_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

supported_versions.each do |zabbix_version|
# path to sql files on Debian and RedHat
path = if Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
path = if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') >= 0
'/usr/share/zabbix-sql-scripts/mysql/'
elsif Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
'/usr/share/doc/zabbix-sql-scripts/mysql/'
else
'/usr/share/doc/zabbix-*-mysql*'
Expand Down
36 changes: 31 additions & 5 deletions spec/classes/database_postgresql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
path = case facts[:os]['name']
when 'CentOS', 'RedHat', 'OracleLinux', 'VirtuozzoLinux'
# Path on RedHat
if Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') >= 0
'/usr/share/zabbix-sql-scripts/postgresql/'
elsif Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
'/usr/share/doc/zabbix-sql-scripts/postgresql/'
else
"/usr/share/doc/zabbix-*-pgsql-#{zabbix_version}*/"
end
else
# Path on Debian
if Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
if Puppet::Util::Package.versioncmp(zabbix_version, '6.0') >= 0
'/usr/share/zabbix-sql-scripts/postgresql/'
elsif Puppet::Util::Package.versioncmp(zabbix_version, '5.4') >= 0
'/usr/share/doc/zabbix-sql-scripts/postgresql/'
else
'/usr/share/doc/zabbix-*-pgsql'
Expand Down Expand Up @@ -80,7 +84,29 @@

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-server:zabbix-server:zabbix-server >> /root/.pgpass') }
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 && psql -h 'node01.example.com' -U 'zabbix-server' -d 'zabbix-server' -f #{sql_server} && 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 && psql -h 'node01.example.com' -U 'zabbix-server' -p 5432 -d 'zabbix-server' -f #{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') }
it { is_expected.to contain_file('/root/.pgpass') }
it { is_expected.to contain_class('zabbix::params') }
end

describe "when zabbix_type is server and version is #{zabbix_version} and custom port is defined" do
let :params do
{
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
database_host: 'node01.example.com',
database_port: 6432,
zabbix_type: 'server',
zabbix_version: zabbix_version
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:6432:zabbix-server:zabbix-server:zabbix-server >> /root/.pgpass') }
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 && psql -h 'node01.example.com' -U 'zabbix-server' -p 6432 -d 'zabbix-server' -f #{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') }
it { is_expected.to contain_file('/root/.pgpass') }
Expand Down Expand Up @@ -127,9 +153,9 @@
it { is_expected.to contain_exec('update_pgpass').with_command('echo node01.example.com:5432:zabbix-proxy:zabbix-proxy:zabbix-proxy >> /root/.pgpass') }

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 && psql -h 'node01.example.com' -U 'zabbix-proxy' -d 'zabbix-proxy' -f schema.sql && touch /etc/zabbix/.schema.done") }
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 && psql -h 'node01.example.com' -U 'zabbix-proxy' -p 5432 -d 'zabbix-proxy' -f schema.sql && touch /etc/zabbix/.schema.done") }
else
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && psql -h 'node01.example.com' -U 'zabbix-proxy' -d 'zabbix-proxy' -f proxy.sql && touch /etc/zabbix/.schema.done") }
it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path} && psql -h 'node01.example.com' -U 'zabbix-proxy' -p 5432 -d 'zabbix-proxy' -f proxy.sql && touch /etc/zabbix/.schema.done") }
end

it { is_expected.to contain_class('zabbix::params') }
Expand Down

0 comments on commit 4e069f9

Please sign in to comment.