Puppet Class: zabbix::database::mysql

Inherits:
zabbix::params
Defined in:
manifests/database/mysql.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 (Optional[Stdlib::Port::Unprivileged]) (defaults to: undef)

    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
71
72
73
74
75
76
77
78
79
80
# File 'manifests/database/mysql.pp', line 13

class zabbix::database::mysql (
  $zabbix_type                                        = '',
  $zabbix_version                                     = $zabbix::params::zabbix_version,
  $database_schema_path                               = '',
  $database_name                                      = '',
  $database_user                                      = '',
  $database_password                                  = '',
  $database_host                                      = '',
  Optional[Stdlib::Port::Unprivileged] $database_port = undef,
  $database_path                                      = $zabbix::params::database_path,
) inherits zabbix::params {
  assert_private()

  if ($database_schema_path == false) or ($database_schema_path == '') {
    if versioncmp($zabbix_version, '6.0') >= 0 {
      $schema_path = '/usr/share/zabbix-sql-scripts/mysql/'
    } else {
      $schema_path = '/usr/share/doc/zabbix-*-mysql*'
    }
  }
  else {
    $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} && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < proxy.sql && touch /etc/zabbix/.schema.done",
        false => "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 = versioncmp($zabbix_version, '6.0') >= 0 ? {
        true  => "cd ${schema_path} && if [ -f server.sql.gz ]; then gunzip -f server.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' ${port}-D '${database_name}' < server.sql && touch /etc/zabbix/.schema.done",
        false => "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"
      }
    }
  }

  # Loading the sql files.
  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',
      }
    }
    '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',
      }
    }
    default  : {
      fail 'We do not work.'
    }
  } # END case $zabbix_type
}