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

Timescaledb #827

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions manifests/database/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# @param database_host Hostname to use to connect to the database
# @param database_port Database port to be used for the import process.
# @param database_path Path to the database executable
# @param manage_database_timescale Import the timescaledb sql file?
# @author Werner Dijkerman <[email protected]>
class zabbix::database::postgresql (
$zabbix_type = '',
Expand All @@ -20,6 +21,7 @@
$database_host = '',
Stdlib::Port::Unprivileged $database_port = 5432,
$database_path = $zabbix::params::database_path,
Boolean $manage_database_timescale = false,
) inherits zabbix::params {
assert_private()

Expand Down Expand Up @@ -108,6 +110,28 @@
provider => 'shell',
require => Exec['update_pgpass'],
}
if $manage_database_timescale {
# Enable timescaledb
$_timescaledb_sql = [
"cd ${schema_path}",
"&& psql -h '${database_host}'",
"-U '${database_user}'",
"-p ${database_port}",
"-d '${database_name}'",
'-f timescaledb.sql',
'&& touch /etc/zabbix/.timescaledb.done',
]
exec { 'zabbix_timescaledb.sql':
command => $_timescaledb_sql.join(' '),
path => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
unless => 'test -f /etc/zabbix/.timescaledb.done',
provider => 'shell',
require => [
Exec['update_pgpass'],
Exec['zabbix_server_data.sql'],
],
}
}
}
default: {
fail 'We do not work.'
Expand Down
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# you can use this parameter to add the database_path to the above mentioned
# path.
# @param manage_database When true, it will configure the database and execute the sql scripts.
# @param manage_database_timescale When true, it will execute the sql scripts needef for timescaledb.
# @param manage_repo When true (default) this module will manage the Zabbix repository.
# @param manage_firewall When true, it will create iptables rules.
# @param manage_service
Expand Down Expand Up @@ -224,6 +225,7 @@
Zabbix::Databases $database_type = $zabbix::params::database_type,
$database_path = $zabbix::params::database_path,
$manage_database = $zabbix::params::manage_database,
$manage_database_timescale = $zabbix::params::manage_database_timescale,
bdeferme marked this conversation as resolved.
Show resolved Hide resolved
$default_vhost = $zabbix::params::default_vhost,
$manage_vhost = $zabbix::params::manage_vhost,
$manage_firewall = $zabbix::params::manage_firewall,
Expand Down Expand Up @@ -401,6 +403,7 @@
manage_firewall => $manage_firewall,
manage_repo => $manage_repo,
manage_database => $manage_database,
manage_database_timescale => $manage_database_timescale,
manage_service => $manage_service,
listenport => $listenport,
sourceip => $sourceip,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
$zabbix_web = 'localhost'
$zabbix_web_ip = '127.0.0.1'
$manage_database = true
$manage_database_timescale = false
$manage_service = true
$default_vhost = false
$manage_firewall = false
Expand Down
23 changes: 13 additions & 10 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# @param zabbix_version This is the zabbix version. Example: 5.0
# @param manage_repo When true (default) this module will manage the Zabbix repository.
# @param manage_database When true, it will configure the database and execute the sql scripts.
# @param manage_database_timescale When true, it will execute the sql scripts needed for timescaledb.
# @param zabbix_package_state The state of the package that needs to be installed: present or latest.
# @param manage_firewall When true, it will create iptables rules.
# @param manage_service
Expand Down Expand Up @@ -172,6 +173,7 @@
Boolean $manage_firewall = $zabbix::params::manage_firewall,
Boolean $manage_repo = $zabbix::params::manage_repo,
Boolean $manage_database = $zabbix::params::manage_database,
Boolean $manage_database_timescale = $zabbix::params::manage_database_timescale,
bdeferme marked this conversation as resolved.
Show resolved Hide resolved
Boolean $manage_service = $zabbix::params::manage_service,
$server_configfile_path = $zabbix::params::server_configfile_path,
$server_config_owner = $zabbix::params::server_config_owner,
Expand Down Expand Up @@ -319,16 +321,17 @@
if $manage_database {
# Execute the postgresql scripts
class { 'zabbix::database::postgresql':
zabbix_type => 'server',
zabbix_version => $zabbix_version,
database_schema_path => $database_schema_path,
database_name => $database_name,
database_user => $database_user,
database_password => $database_password,
database_host => $database_host,
database_port => $database_port,
database_path => $database_path,
require => $zabbix_database_require,
zabbix_type => 'server',
zabbix_version => $zabbix_version,
database_schema_path => $database_schema_path,
database_name => $database_name,
database_user => $database_user,
database_password => $database_password,
database_host => $database_host,
database_port => $database_port,
database_path => $database_path,
manage_database_timescale => $manage_database_timescale,
require => $zabbix_database_require,
}
}
}
Expand Down
47 changes: 47 additions & 0 deletions spec/classes/database_postgresql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,53 @@
it { is_expected.to contain_class('zabbix::params') }
end

describe "when zabbix_type is server and version is #{zabbix_version} and manage_database_timescale is true" do
let :params do
{
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
database_host: 'node01.example.com',
zabbix_type: 'server',
zabbix_version: zabbix_version,
manage_database_timescale: true
}
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") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Suggested change
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_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") }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bdeferme - just curious if you saw this. Asking because I came here looking for the timescaledb support

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

describe "when zabbix_type is server and version is #{zabbix_version} and manage_database_timescale is true 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,
manage_database_timescale: true
}
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') }
it { is_expected.to contain_class('zabbix::params') }
it { is_expected.to contain_exec('zabbix_timescaledb.sql').with_command("cd #{path} && psql -h 'node01.example.com' -U 'zabbix-server' -p 6432 -d 'zabbix-server' -f timescaledb.sql && touch /etc/zabbix/.timescaledb.done") }
end

describe "when zabbix_type is proxy and version is #{zabbix_version}" do
let :params do
{
Expand Down