Puppet Class: icinga2::feature::icingadb

Defined in:
manifests/feature/icingadb.pp

Summary

Configures the Icinga 2 feature icingadb.

Overview

Parameters:

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

    Set to present, enables the feature icingadb, absent disabled it.

  • host (Optional[Stdlib::Host]) (defaults to: undef)

    IcingaDB Redis host address.

  • port (Optional[Stdlib::Port]) (defaults to: undef)

    IcingaDB Redis port.

  • socket_path (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    IcingaDB Redis unix sockt. Can be used instead of host and port attributes.

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

    Timeout for establishing new connections.

  • password (Optional[Icinga::Secret]) (defaults to: undef)

    IcingaDB Redis password. The password parameter isn’t parsed anymore.

  • env_id (Optional[Icinga::Secret]) (defaults to: undef)

    The ID is used in all Icinga DB components to separate data from multiple different environments and is written to the file ‘/var/lib/icinga2/icingadb.env` by Icinga 2. Icinga 2 generates a unique environment ID from its CA certificate when it is first started with the Icinga DB feature enabled.

  • enable_tls (Boolean) (defaults to: false)

    Either enable or disable SSL/TLS. Other SSL parameters are only affected if this is set to ‘true’.

  • tls_key_file (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Location of the private key. Only valid if tls is enabled.

  • tls_cert_file (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Location of the certificate. Only valid if tls is enabled.

  • tls_cacert_file (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Location of the CA certificate. Only valid if tls is enabled.

  • tls_crl_file (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Location of the Certicicate Revocation List. Only valid if tls is enabled.

  • tls_key (Optional[Icinga::Secret]) (defaults to: undef)

    The private key in a PEM formated string to store spicified in tls_key_file. Only valid if tls is enabled.

  • tls_cert (Optional[String[1]]) (defaults to: undef)

    The certificate in a PEM format string to store spicified in tls_cert_file. Only valid if tls is enabled.

  • tls_cacert (Optional[String[1]]) (defaults to: undef)

    The CA root certificate in a PEM formated string to store spicified in tls_cacert_file. Only valid if tls is enabled.

  • tls_capath (Optional[String[1]]) (defaults to: undef)

    Path to all trusted CA certificates. Only valid if tls is enabled.

  • tls_cipher (Optional[String[1]]) (defaults to: undef)

    List of allowed ciphers. Only valid if tls is enabled.

  • tls_protocolmin (Optional[String[1]]) (defaults to: undef)

    Minimum TLS protocol version like ‘TLSv1.2`. Only valid if tls is enabled.

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

    Whether not to verify the peer.



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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'manifests/feature/icingadb.pp', line 67

class icinga2::feature::icingadb (
  Enum['absent', 'present']      $ensure          = present,
  Optional[Stdlib::Host]         $host            = undef,
  Optional[Stdlib::Port]         $port            = undef,
  Optional[Stdlib::Absolutepath] $socket_path     = undef,
  Optional[Icinga2::Interval]    $connect_timeout = undef,
  Optional[Icinga::Secret]       $password        = undef,
  Optional[Icinga::Secret]       $env_id          = undef,
  Boolean                        $enable_tls      = false,
  Optional[Stdlib::Absolutepath] $tls_key_file    = undef,
  Optional[Stdlib::Absolutepath] $tls_cert_file   = undef,
  Optional[Stdlib::Absolutepath] $tls_cacert_file = undef,
  Optional[Stdlib::Absolutepath] $tls_crl_file    = undef,
  Optional[Icinga::Secret]       $tls_key         = undef,
  Optional[String[1]]            $tls_cert        = undef,
  Optional[String[1]]            $tls_cacert      = undef,
  Optional[String[1]]            $tls_capath      = undef,
  Optional[String[1]]            $tls_cipher      = undef,
  Optional[String[1]]            $tls_protocolmin = undef,
  Optional[Boolean]              $tls_noverify    = undef,
) {
  if ! defined(Class['icinga2']) {
    fail('You must include the icinga2 base class before using any icinga2 feature class!')
  }

  $conf_dir = $icinga2::globals::conf_dir
  $data_dir = $icinga2::globals::data_dir
  $cert_dir = $icinga2::globals::cert_dir
  $owner    = $icinga2::globals::user
  $group    = $icinga2::globals::group

  $_password = if $password =~ Sensitive {
    $password
  } elsif $password =~ String {
    Sensitive($password)
  } else {
    undef
  }

  $_notify = $ensure ? {
    'present' => Class['icinga2::service'],
    default   => undef,
  }

  if $env_id {
    file { "${data_dir}/icingadb.env":
      ensure    => file,
      owner     => $owner,
      group     => $group,
      mode      => '0600',
      seltype   => 'icinga2_etc_t',
      content   => sprintf('"%s"', unwrap($env_id)),
      show_diff => false,
      tag       => 'icinga2::config::file',
    }
  }

  if $enable_tls {
    $cert = icinga::cert::files(
      'IcingaDB-icingadb',
      $cert_dir,
      $tls_key_file,
      $tls_cert_file,
      $tls_cacert_file,
      $tls_key,
      $tls_cert,
      $tls_cacert,
    )

    $attrs_tls = {
      'enable_tls'        => true,
      'ca_path'           => $cert['cacert_file'],
      'cert_path'         => $cert['cert_file'],
      'key_path'          => $cert['key_file'],
      'crl_path'          => $tls_crl_file,
      'insecure_noverify' => $tls_noverify,
      'cipher_list'       => $tls_cipher,
      'tls_protocolmin'   => $tls_protocolmin,
    }

    # Workaround, icinga::cert doesn't accept undef values for owner and group!
    if $facts['os']['family'] != 'windows' {
      icinga::cert { 'IcingaDB-icingadb':
        args   => $cert,
        owner  => $owner,
        group  => $group,
        notify => $_notify,
      }
    } else {
      icinga::cert { 'IcingaDB-icingadb':
        args   => $cert,
        owner  => 'foo',
        group  => 'bar',
        notify => $_notify,
      }
    }
  } # enable_tls
  else {
    $attrs_tls = {
      'enable_tls'        => undef,
      'ca_path'           => undef,
      'cert_path'         => undef,
      'key_path'          => undef,
      'crl_path'          => undef,
      'insecure_noverify' => undef,
      'cipher_list'       => undef,
      'tls_protocolmin'   => undef,
    }
    $cert      = {}
  }

  # compose attributes
  $attrs = {
    'host'     => $host,
    'port'     => $port,
    'path'     => $socket_path,
    'password' => $_password,
  }

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

  # manage feature
  icinga2::feature { 'icingadb':
    ensure => $ensure,
  }
}