Puppet Class: icinga2::feature::idopgsql

Defined in:
manifests/feature/idopgsql.pp

Summary

Installs and configures the Icinga 2 feature ido-pgsql.

Overview

Examples:

The ido-pgsql featue requires an existing database and a user with permissions. This example uses the [puppetlab/postgresql](forge.puppet.com/puppetlabs/postgresql) module.

include icinga2
include postgresql::server

postgresql::server::db { 'icinga2':
  user     => 'icinga2',
  password => postgresql_password('icinga2', 'supersecret'),
}

class{ 'icinga2::feature::idopgsql':
  user          => 'icinga2',
  password      => 'supersecret',
  database      => 'icinga2',
  import_schema => true,
  require       => Postgresql::Server::Db['icinga2']
}

Parameters:

  • ensure (Enum['absent', 'present']) (defaults to: present)

    Set to present enables the feature ido-pgsql, absent disables it.

  • host (Stdlib::Host) (defaults to: 'localhost')

    PostgreSQL database host address.

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

    PostgreSQL database port.

  • user (String) (defaults to: 'icinga')

    PostgreSQL database user with read/write permission to the icinga database.

  • password (String)

    PostgreSQL database user’s password. The password parameter isn’t parsed anymore.

  • database (String) (defaults to: 'icinga')

    PostgreSQL database name.

  • table_prefix (Optional[String]) (defaults to: undef)

    PostgreSQL database table prefix.

  • instance_name (Optional[String]) (defaults to: undef)

    Unique identifier for the local Icinga 2 instance.

  • instance_description (Optional[String]) (defaults to: undef)

    Description of the Icinga 2 instance.

  • enable_ha (Optional[Boolean]) (defaults to: undef)

    Enable the high availability functionality. Only valid in a cluster setup.

  • failover_timeout (Optional[Icinga2::Interval]) (defaults to: undef)

    Set the failover timeout in a HA cluster. Must not be lower than 60s.

  • cleanup (Optional[Hash]) (defaults to: undef)

    Hash with items for historical table cleanup.

  • categories (Optional[Array]) (defaults to: undef)

    Array of information types that should be written to the database.

  • import_schema (Boolean) (defaults to: false)

    Whether to import the PostgreSQL schema or not.



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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'manifests/feature/idopgsql.pp', line 63

class icinga2::feature::idopgsql(
  String                         $password,
  Enum['absent', 'present']      $ensure               = present,
  Stdlib::Host                   $host                 = 'localhost',
  Stdlib::Port::Unprivileged     $port                 = 5432,
  String                         $user                 = 'icinga',
  String                         $database             = 'icinga',
  Optional[String]               $table_prefix         = undef,
  Optional[String]               $instance_name        = undef,
  Optional[String]               $instance_description = undef,
  Optional[Boolean]              $enable_ha            = undef,
  Optional[Icinga2::Interval]    $failover_timeout     = undef,
  Optional[Hash]                 $cleanup              = undef,
  Optional[Array]                $categories           = undef,
  Boolean                        $import_schema        = false,
) {

  if ! defined(Class['::icinga2']) {
    fail('You must include the icinga2 base class before using any icinga2 feature class!')
  }

  $conf_dir               = $::icinga2::globals::conf_dir
  $ido_pgsql_package_name = $::icinga2::globals::ido_pgsql_package_name
  $ido_pgsql_schema       = $::icinga2::globals::ido_pgsql_schema
  $manage_package         = $::icinga2::manage_package
  $manage_packages        = $::icinga2::manage_packages
  $_notify                = $ensure ? {
    'present' => Class['::icinga2::service'],
    default   => undef,
  }

  $attrs = {
    host                  => $host,
    port                  => $port,
    user                  => $user,
    password              => "-:\"${password}\"",   # The password parameter isn't parsed anymore.
    database              => $database,
    table_prefix          => $table_prefix,
    instance_name         => $instance_name,
    instance_description  => $instance_description,
    enable_ha             => $enable_ha,
    failover_timeout      => $failover_timeout,
    cleanup               => $cleanup,
    categories            => $categories,
  }

  # install additional package
  if $ido_pgsql_package_name and ($manage_package or $manage_packages) {
    if $::osfamily == 'debian' {
      ensure_resources('file', { '/etc/dbconfig-common' => { ensure => directory, owner => 'root', group => 'root' } })
      file { "/etc/dbconfig-common/${ido_pgsql_package_name}.conf":
        ensure  => file,
        content => "dbc_install='false'\ndbc_upgrade='false'\ndbc_remove='false'\n",
        owner   => 'root',
        group   => 'root',
        mode    => '0600',
        before  => Package[$ido_pgsql_package_name],
      }
    } # Debian

    package { $ido_pgsql_package_name:
      ensure => installed,
      before => Icinga2::Feature['ido-pgsql'],
    }
  }

  # import db schema
  if $import_schema {
    if $ido_pgsql_package_name and ($manage_package or $manage_packages) {
      Package[$ido_pgsql_package_name] -> Exec['idopgsql-import-schema']
    }
    exec { 'idopgsql-import-schema':
      user        => 'root',
      path        => $::path,
      environment => ["PGPASSWORD=${password}"],
      command     => "psql -h '${host}' -U '${user}' -p '${port}' -d '${database}' -w -f \"${ido_pgsql_schema}\"",
      unless      => "psql -h '${host}' -U '${user}' -p '${port}' -d '${database}' -w -c 'select version from icinga_dbversion'",
    }
  }

  # create object
  icinga2::object { 'icinga2::object::IdoPgsqlConnection::ido-pgsql':
    object_name => 'ido-pgsql',
    object_type => 'IdoPgsqlConnection',
    attrs       => delete_undef_values($attrs),
    attrs_list  => keys($attrs),
    target      => "${conf_dir}/features-available/ido-pgsql.conf",
    order       => 10,
    notify      => $_notify,
  }

  # import library
  concat::fragment { 'icinga2::feature::ido-pgsql':
    target  => "${conf_dir}/features-available/ido-pgsql.conf",
    content => "library \"db_ido_pgsql\"\n\n",
    order   => '05',
  }

  icinga2::feature { 'ido-pgsql':
    ensure  => $ensure,
  }
}