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

Zabbix-proxy install database population #62

Closed
simon-kerckhof opened this issue Mar 18, 2015 · 6 comments
Closed

Zabbix-proxy install database population #62

simon-kerckhof opened this issue Mar 18, 2015 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@simon-kerckhof
Copy link

The database population script for the zabbix-proxy-mysql package is run with the command below:

command => "cd ${schema_path} && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' -D '${database_name}' < schema.sql && touch /etc/zabbix/.schema.done",

Because the schema.sql is gzipped into schema.sql.gz on Ubuntu 14.04 LTS, the command fails.
It should be altered with a small if-loop that checks if the file is gzipped:

command => "cd ${schema_path} && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && mysql -h '${database_host}' -u '${database_user}' -p'${database_password}' -D '${database_name}' < schema.sql && touch /etc/zabbix/.schema.done",

@dj-wasabi
Copy link
Contributor

Hi simon-kerckhof,

Thank you for making time to create this issue!
Will take a look at it.

Kind regards,
Werner

@dj-wasabi dj-wasabi added the bug Something isn't working label Mar 19, 2015
@dj-wasabi dj-wasabi added this to the 1.3.0 milestone Apr 2, 2015
dj-wasabi pushed a commit that referenced this issue Apr 7, 2015
@dj-wasabi
Copy link
Contributor

Hi simon-kerckhof,

I just pushed an fix for this.
Please let me know if something isn't working as it supposed to.

Kind regards,
Werner

@PHaroZ
Copy link

PHaroZ commented May 25, 2015

puppetlabs/postgresql v4.3.0
wdijkerman/zabbix v1.4.0

same issue on postgresql with {data,images,schema}.sql

@dj-wasabi
Copy link
Contributor

Hi PHaroZ,

So these are also found on the system as {data,images,schema}.sql.gz ?

Kind regards,
Werner

@PHaroZ
Copy link

PHaroZ commented May 25, 2015

yep, I've juste edit my postgres.pp as mentioned by simon.

It results as

cat manifests/database/postgresql.pp 
# == 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
#
# Copyright 2014 Werner Dijkerman
#
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,
) {
# Allow to customize the path to the Database Schema,
  if ! $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
  }


  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  => "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",
        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  => "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",
        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  => "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",
        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  => "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",
        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.'
    }
  }
}

@dj-wasabi dj-wasabi modified the milestones: 1.5.0, 1.3.0 May 26, 2015
dj-wasabi pushed a commit that referenced this issue May 26, 2015
@dj-wasabi
Copy link
Contributor

Hi PHaroZ,

It is also done now in the module.

Kind regards,
Werner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants