Puppet Class: zabbix::database::postgresql

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

Overview

Class: zabbix::database::postgresql

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

Please note:
This class will be called from zabbix::database. No need for calling
this class manually.

Authors

Author Name: ikben@werner-dijkerman.nl

Copyright 2014 Werner Dijkerman

Parameters:

  • zabbix_type (Any) (defaults to: '')
  • zabbix_version (Any) (defaults to: $zabbix::params::zabbix_version)
  • database_schema_path (Any) (defaults to: '')
  • database_name (Any) (defaults to: '')
  • database_user (Any) (defaults to: '')
  • database_password (Any) (defaults to: '')
  • database_host (Any) (defaults to: '')
  • database_path (Any) (defaults to: $zabbix::params::database_path)


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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'manifests/database/postgresql.pp', line 18

class zabbix::database::postgresql (
  $zabbix_type          = '',
  $zabbix_version       = $zabbix::params::zabbix_version,
  $database_schema_path = '',
  $database_name        = '',
  $database_user        = '',
  $database_password    = '',
  $database_host        = '',
  $database_path        = $zabbix::params::database_path,
) inherits zabbix::params {
  #
  # Adjustments for version 3.0 - structure of package with sqls differs from previous versions
  case $zabbix_version {
    '3.0': {
      if ($database_schema_path == false) or ($database_schema_path == '') {
        case $::operatingsystem {
          'CentOS', 'RedHat', 'OracleLinux': {
            $schema_path   = "/usr/share/doc/zabbix-*-pgsql-${zabbix_version}*/"
          }
          default : {
            $schema_path   = '/usr/share/doc/zabbix-*-pgsql'
          }
        }
      }
      else {
        $schema_path = $database_schema_path
      }

      case $zabbix_type {
        'proxy': {
          $zabbix_proxy_create_sql = "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -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 create.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -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'
        }
      }
    }
    default: {
      if ($database_schema_path == false) or ($database_schema_path == '') {
        case $::operatingsystem {
          'CentOS', 'RedHat', 'OracleLinux': {
            $schema_path   = "/usr/share/doc/zabbix-*-pgsql-${zabbix_version}*/create"
          }
          default : {
            $schema_path   = '/usr/share/zabbix-*-pgsql'
          }
        }
      }
      else {
        $schema_path = $database_schema_path
      }
      case $zabbix_type {
        'proxy': {
          $zabbix_proxy_create_sql = "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
        }
        default: {
          $zabbix_server_create_sql = "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -d '${database_name}' -f schema.sql && touch /etc/zabbix/.schema.done"
          $zabbix_server_images_sql = "cd ${schema_path} && if [ -f images.sql.gz ]; then gunzip images.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -d '${database_name}' -f images.sql && touch /etc/zabbix/.images.done"
          $zabbix_server_data_sql   = "cd ${schema_path} && if [ -f data.sql.gz ]; then gunzip data.sql.gz ; fi && psql -h '${database_host}' -U '${database_user}' -d '${database_name}' -f data.sql && touch /etc/zabbix/.data.done"
        }
      }
    }
  }

  exec { 'update_pgpass':
    command => "echo ${database_host}:5432:${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",
    require => File['/root/.pgpass'],
  }

  file { '/root/.pgpass':
    ensure  => present,
    mode    => '0600',
    owner   => 'root',
    group   => 'root',
    require => Class['postgresql::client'],
  }

  case $zabbix_type {
      'proxy': {
        exec { 'zabbix_proxy_create.sql':
          command  => $zabbix_proxy_create_sql,
          path     => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
          unless   => 'test -f /etc/zabbix/.schema.done',
          provider => 'shell',
          require  => [
            Exec['update_pgpass'],
          ],
        }
      }
      'server': {
        exec { 'zabbix_server_create.sql':
          command  => $zabbix_server_create_sql,
          path     => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
          unless   => 'test -f /etc/zabbix/.schema.done',
          provider => 'shell',
          require  => [
            Exec['update_pgpass'],
          ],
        } ->
        exec { 'zabbix_server_images.sql':
          command  => $zabbix_server_images_sql,
          path     => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
          unless   => 'test -f /etc/zabbix/.images.done',
          provider => 'shell',
          require  => [
            Exec['update_pgpass'],
          ],
        } ->
        exec { 'zabbix_server_data.sql':
          command  => $zabbix_server_data_sql,
          path     => "/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:${database_path}",
          unless   => 'test -f /etc/zabbix/.data.done',
          provider => 'shell',
          require  => [
            Exec['update_pgpass'],
          ],
        }
      }
    default: {
      fail 'We do not work.'
    }
  }
}