Puppet Class: zabbix::database::postgresql

Inherits:
zabbix::params
Defined in:
manifests/database/postgresql.pp

Summary

This will install and load the sql files for the tables and other data which is needed for zabbix.

Overview

Parameters:

  • zabbix_type (Any) (defaults to: '')

    Zabbix component type. Can be one of: proxy, server

  • zabbix_version (Any) (defaults to: $zabbix::params::zabbix_version)

    This is the zabbix version

  • database_schema_path (Any) (defaults to: '')

    The path to the directory containing the .sql schema files

  • database_name (Any) (defaults to: '')

    Name of the database to connect to

  • database_user (Any) (defaults to: '')

    Username to use to connect to the database

  • database_password (Any) (defaults to: '')

    Password to use to connect to the database

  • database_host (Any) (defaults to: '')

    Hostname to use to connect to the database

  • database_port (Stdlib::Port::Unprivileged) (defaults to: 5432)

    Database port to be used for the import process.

  • database_path (Any) (defaults to: $zabbix::params::database_path)

    Path to the database executable

Author:

  • Werner Dijkerman <ikben@werner-dijkerman.nl>



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'manifests/database/postgresql.pp', line 13

class zabbix::database::postgresql (
  $zabbix_type                                        = '',
  $zabbix_version                                     = $zabbix::params::zabbix_version,
  $database_schema_path                               = '',
  $database_name                                      = '',
  $database_user                                      = '',
  $database_password                                  = '',
  $database_host                                      = '',
  Stdlib::Port::Unprivileged $database_port           = 5432,
  $database_path                                      = $zabbix::params::database_path,
) inherits zabbix::params {
  assert_private()

  if $database_schema_path != false and $database_schema_path != '' {
    $schema_path = $database_schema_path
  } elsif versioncmp($zabbix_version, '6.0') >= 0 {
    $schema_path = '/usr/share/zabbix-sql-scripts/postgresql/'
  } elsif $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '7' {
    $schema_path = "/usr/share/doc/zabbix-*-pgsql-${zabbix_version}*/"
  } else {
    $schema_path = '/usr/share/doc/zabbix-*-pgsql'
  }

  $done_file = '/etc/zabbix/.schema.done'
  $schema_file = case $zabbix_type {
    'proxy': {
      if versioncmp($zabbix_version, '6.0') >= 0 {
        'proxy.sql'
      } else {
        'schema.sql'
      }
    }
    default: {
      if versioncmp($zabbix_version, '6.0') >= 0 {
        'server.sql'
      } else {
        'create.sql'
      }
    }
  }

  $command = "cd ${schema_path} && if [ -f ${schema_file}.gz ]; then zcat ${schema_file}.gz | psql ; else psql -f ${schema_file}; fi && touch ${done_file}"
  $exec_env = [
    "PGHOST=${database_host}",
    "PGPORT=${database_port}",
    "PGUSER=${database_user}",
    "PGPASSWORD=${database_password}",
    "PGDATABASE=${database_name}",
  ]

  exec { 'zabbix_create.sql':
    command     => $command,
    path        => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
    creates     => $done_file,
    provider    => 'shell',
    environment => $exec_env,
  }
}