Allow non-default port database importing
MODIFY
manifests/database/mysql.pp
manifests/database/mysql.pp
# This class will be called from zabbix::server or zabbix::proxy.
# No need for calling this class manually.
#
+# === Parameters
+#
+# [*database_port*]
+# Database port to be used for the import process.
+#
# === Authors
#
# Author Name: ikben@werner-dijkerman.nl
@@ -23,6 +28,7 @@ class zabbix::database::mysql (
$database_user = '',
$database_password = '',
$database_host = '',
+ Optional[Stdlib::Port::Unprivileged] $database_port = undef,
$database_path = $zabbix::params::database_path,
) inherits zabbix::params {
assert_private()
@@ -34,12 +40,18 @@ class zabbix::database::mysql (
$schema_path = $database_schema_path
}
+ if $database_port != undef {
+ $port = "-P ${database_port} "
+ } else {
+ $port = ''
+ }
+
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}' -D '${database_name}' < schema.sql && touch /etc/zabbix/.schema.done"
+ $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"
}
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}' -D '${database_name}' < create.sql && touch /etc/zabbix/.schema.done"
+ $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_images_sql = 'touch /etc/zabbix/.images.done'
$zabbix_server_data_sql = 'touch /etc/zabbix/.data.done'
}

MODIFY
manifests/database/postgresql.pp
manifests/database/postgresql.pp
# This class will be called from zabbix::server or zabbix::proxy.
# No need for calling this class manually.
#
+# === Parameters
+#
+# [*database_port*]
+# Database port to be used for the import process.
+#
# === Authors
#
# Author Name: ikben@werner-dijkerman.nl
@@ -23,6 +28,7 @@ class zabbix::database::postgresql (
$database_user = '',
$database_password = '',
$database_host = '',
+ Optional[Stdlib::Port::Unprivileged] $database_port = undef,
$database_path = $zabbix::params::database_path,
) inherits zabbix::params {
assert_private()
@@ -40,12 +46,18 @@ class zabbix::database::postgresql (
$schema_path = $database_schema_path
}
+ if $database_port != undef {
+ $port = "-p ${database_port} "
+ } else {
+ $port = ''
+ }
+
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}' -d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
+ $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"
}
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}' -d '${database_name}' -f create.sql && touch /etc/zabbix/.schema.done"
+ $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_images_sql = 'touch /etc/zabbix/.images.done'
$zabbix_server_data_sql = 'touch /etc/zabbix/.data.done'
}

MODIFY
manifests/proxy.pp
manifests/proxy.pp
@@ -493,6 +493,7 @@ class zabbix::proxy (
database_user => $database_user,
database_password => $database_password,
database_host => $database_host,
+ database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-proxy-${db}"],
}
@@ -507,6 +508,7 @@ class zabbix::proxy (
database_user => $database_user,
database_password => $database_password,
database_host => $database_host,
+ database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-proxy-${db}"],
}

MODIFY
manifests/server.pp
manifests/server.pp
@@ -307,7 +307,7 @@ class zabbix::server (
$database_user = $zabbix::params::server_database_user,
$database_password = $zabbix::params::server_database_password,
$database_socket = $zabbix::params::server_database_socket,
- $database_port = $zabbix::params::server_database_port,
+ Optional[Stdlib::Port::Unprivileged] $database_port = $zabbix::params::server_database_port,
$startpollers = $zabbix::params::server_startpollers,
$startipmipollers = $zabbix::params::server_startipmipollers,
$startpollersunreachable = $zabbix::params::server_startpollersunreachable,
@@ -399,6 +399,7 @@ class zabbix::server (
database_user => $database_user,
database_password => $database_password,
database_host => $database_host,
+ database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-server-${db}"],
}
@@ -417,6 +418,7 @@ class zabbix::server (
database_user => $database_user,
database_password => $database_password,
database_host => $database_host,
+ database_port => $database_port,
database_path => $database_path,
require => Package["zabbix-server-${db}"],
}

MODIFY
spec/classes/database_mysql_spec.rb
spec/classes/database_mysql_spec.rb
@@ -26,6 +26,27 @@ describe 'zabbix::database::mysql' do
%w[4.0 5.0 5.2].each do |zabbix_version|
context "when zabbix_type is server and zabbix version is #{zabbix_version}" do
+ describe 'and database_port is defined' do
+ let :params do
+ {
+ database_name: 'zabbix-server',
+ database_user: 'zabbix-server',
+ database_password: 'zabbix-server',
+ database_host: 'rspec.puppet.com',
+ database_port: 3306,
+ zabbix_type: 'server',
+ zabbix_version: zabbix_version
+ }
+ end
+
+ 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_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
+
+ describe 'and no database_port is defined' do
let :params do
{
database_name: 'zabbix-server',
@@ -42,8 +63,29 @@ describe 'zabbix::database::mysql' do
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_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
+ describe "and database_port is defined" do
+ let :params do
+ {
+ database_name: 'zabbix-proxy',
+ database_user: 'zabbix-proxy',
+ database_password: 'zabbix-proxy',
+ database_host: 'rspec.puppet.com',
+ database_port: 3306,
+ zabbix_type: 'proxy',
+ zabbix_version: zabbix_version
+ }
+ end
+
+ 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") }
+ end
- describe "when zabbix_type is proxy and zabbix version is #{zabbix_version}" do
+ describe "and no database_port is defined" do
let :params do
{
database_name: 'zabbix-proxy',

MODIFY
spec/classes/database_postgresql_spec.rb
spec/classes/database_postgresql_spec.rb
@@ -36,6 +36,28 @@ describe 'zabbix::database::postgresql' do
end
describe "when zabbix_type is server and version is #{zabbix_version}" do
+ let :params do
+ {
+ database_name: 'zabbix-server',
+ database_user: 'zabbix-server',
+ database_password: 'zabbix-server',
+ database_host: 'node01.example.com',
+ database_port: 5432,
+ 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:5432:zabbix-server:zabbix-server:zabbix-server >> /root/.pgpass') }
+ it { is_expected.to contain_exec('zabbix_server_create.sql').with_command("cd #{path_for3_and_up} && if [ -f create.sql.gz ]; then gunzip -f create.sql.gz ; fi && psql -h 'node01.example.com' -U 'zabbix-server' -p 5432 -d 'zabbix-server' -f create.sql && 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 no port is defined" do
let :params do
{
database_name: 'zabbix-server',
@@ -57,6 +79,25 @@ describe 'zabbix::database::postgresql' do
end
describe "when zabbix_type is proxy and version is #{zabbix_version}" do
+ let :params do
+ {
+ database_name: 'zabbix-proxy',
+ database_user: 'zabbix-proxy',
+ database_password: 'zabbix-proxy',
+ database_host: 'node01.example.com',
+ database_port: 5432,
+ zabbix_type: 'proxy',
+ 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:5432:zabbix-proxy:zabbix-proxy:zabbix-proxy >> /root/.pgpass') }
+ it { is_expected.to contain_exec('zabbix_proxy_create.sql').with_command("cd #{path_for3_and_up} && 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") }
+ it { is_expected.to contain_class('zabbix::params') }
+ end
+
+ describe "when zabbix_type is proxy and version is #{zabbix_version} and no port is defined" do
let :params do
{
database_name: 'zabbix-proxy',

MODIFY
spec/classes/server_spec.rb
spec/classes/server_spec.rb
@@ -204,7 +204,7 @@ describe 'zabbix::server' do
database_host: 'localhost',
database_name: 'zabbix-server',
database_password: 'zabbix-server',
- database_port: '3306',
+ database_port: 3306,
database_schema: 'zabbix-server',
database_socket: '/tmp/socket.db',
database_user: 'zabbix-server',

Allow non-default port database importing

Signed-off-by: Christos Papageorgiou <root.expert.xda@gmail.com>