Puppet Class: psick::icingaweb2

Defined in:
manifests/icingaweb2.pp

Overview

This class manages the installation and initialisation of icingaweb2

Parameters:

  • ensure (String) (defaults to: 'present')

    If to install or remove icingaweb2

  • manage (Boolean) (defaults to: $::psick::manage)

    If to actually manage any resource in this profile or not

  • module (Enum['psick','icinga']) (defaults to: 'psick')

    What module to use to install icingaweb2: psick or icingaweb2

  • auto_prereq (Boolean) (defaults to: $::psick::auto_prereq)

    If to automatically install all the prerequisites resources needed to install Icingaweb2 (used with $module == psick)

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

    The path of the erb template (as used in template()) to use to populate the main Icingaweb configuration file. (used with $module == psick)

  • options (Hash) (defaults to: { })

    An open hash of options you may use in your template (used with $module == psick)

  • tp_conf_hash (Hash) (defaults to: { })

    An open hash of tp::conf resources to manage any icingaweb related configuration file (used with $module == psick)

  • webserver_class (Optional[String]) (defaults to: '::tp_profile::apache')

    What class to use to manage the webserver. No dedicated class is used if value is empty or undef

  • dbserver_class (Optional[String]) (defaults to: '::tp_profile::mariadb')

    What class to use to manage the dbserver. No dedicated class is used if value is empty or undef

  • db_backend (Optional[Enum['mysql','mariadb','pgsql']]) (defaults to: 'mysql')

    What database backend to use for icingaweb2. If set, relevant client packages are installed

  • fix_php_timezone (Boolean) (defaults to: true)

    If to set the timezone as in $::psick::timezone on php.ini

  • no_noop (Boolean) (defaults to: false)

    Set noop metaparameter to false to all the resources of this class. This overrides client site noop setting but not $psick::noop_mode.

  • icingaweb2_params (Hash) (defaults to: {})
  • db_manage (Boolean) (defaults to: true)
  • db_settings (Hash) (defaults to: {})
  • director_db_manage (Boolean) (defaults to: false)
  • director_db_backend (Optional[Enum['mysql','mariadb','pgsql']]) (defaults to: 'mysql')
  • director_db_settings (Hash) (defaults to: {})
  • config_backend (Enum['ini','db']) (defaults to: 'db')
  • ido_settings (Hash) (defaults to: lookup('psick::icinga2::ido_settings'))
  • install_icingaweb2_selinux (Boolean) (defaults to: false)
  • php_fpm_manage (Boolean) (defaults to: true)
  • php_fpm_name (String) (defaults to: 'php-fpm')
  • monitoring_module_manage (Boolean) (defaults to: true)
  • monitoring_module_params (Hash) (defaults to: {})
  • api_user_manage (Boolean) (defaults to: true)
  • api_host (String) (defaults to: pick($::psick::icinga2::master,$clientcert))
  • api_user (String) (defaults to: 'icingaweb2')
  • api_password (String) (defaults to: 'icingaweb2apiuser')
  • api_user_permissions (Array) (defaults to: [ 'status/query', 'actions/*', 'objects/modify/*', 'objects/query/*' ])
  • puppetdb_module_manage (Boolean) (defaults to: false)
  • puppetdb_module_params (Hash) (defaults to: {})
  • director_module_manage (Boolean) (defaults to: false)
  • director_module_params (Hash) (defaults to: {})
  • grafana_module_manage (Boolean) (defaults to: true)
  • grafana_module_params (Hash) (defaults to: {})
  • influxdb_settings (Hash) (defaults to: lookup('psick::icinga2::influxdb_settings'))
  • grafana_manage (Boolean) (defaults to: true)
  • grafana_params (Hash) (defaults to: {})
  • grafana_settings (Hash) (defaults to: {})
  • extra_modules (Hash) (defaults to: { })
  • git_manage (Boolean) (defaults to: true)


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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'manifests/icingaweb2.pp', line 27

class psick::icingaweb2 (
  String                 $ensure          = 'present',
  Boolean                $manage          = $::psick::manage,
  Enum['psick','icinga'] $module          = 'psick',
  Boolean                $auto_prereq     = $::psick::auto_prereq,
  Hash                $icingaweb2_params = {},

  Optional[String]       $webserver_class = '::tp_profile::apache',
  Optional[String]       $dbserver_class  = '::tp_profile::mariadb',
  Optional[String]       $template        = undef,
  Hash                   $options         = { },
  Hash                   $tp_conf_hash    = { },

  Boolean $db_manage                      = true,
  Optional[Enum['mysql','mariadb','pgsql']] $db_backend = 'mysql',
  Hash $db_settings                       = {},

  Boolean $director_db_manage             = false,
  Optional[Enum['mysql','mariadb','pgsql']] $director_db_backend = 'mysql',
  Hash $director_db_settings              = {},

  Enum['ini','db'] $config_backend        = 'db',

  Hash $ido_settings                      = lookup('psick::icinga2::ido_settings'),

  Boolean $fix_php_timezone               = true,
  Boolean $install_icingaweb2_selinux     = false,
  Boolean $php_fpm_manage                 = true,
  String $php_fpm_name                    = 'php-fpm',

  Boolean $monitoring_module_manage       = true,
  Hash $monitoring_module_params          = {},

  Boolean $api_user_manage                = true,
  String $api_host                        = pick($::psick::icinga2::master,$clientcert),
  String $api_user                        = 'icingaweb2',
  String $api_password                    = 'icingaweb2apiuser',
  Array $api_user_permissions             = [ 'status/query', 'actions/*', 'objects/modify/*', 'objects/query/*' ],

  Boolean $puppetdb_module_manage         = false,
  Hash $puppetdb_module_params            = {},

  Boolean $director_module_manage         = false,
  Hash $director_module_params            = {},

  Boolean $grafana_module_manage          = true,
  Hash $grafana_module_params             = {},
  Hash $influxdb_settings                 = lookup('psick::icinga2::influxdb_settings'),

  Boolean $grafana_manage                 = true,
  Hash $grafana_params                    = {},
  Hash $grafana_settings                  = {},

  Hash $extra_modules                     = { },

  Boolean $git_manage                     = true,

  Boolean $no_noop                        = false,
) {

  if $manage {
    if !$::psick::noop_mode and $no_noop {
      info('Forced no-noop mode in psick::icingaweb2')
      noop(false)
    }
    if $webserver_class and $webserver_class != '' {
      contain $webserver_class
      Class['icingaweb2'] ~> Class[$webserver_class]
    }
    if $dbserver_class and $dbserver_class != '' {
      contain $dbserver_class
      Class[$dbserver_class] -> Psick::Mariadb::Grant<||>
      Class[$dbserver_class] -> Psick::Mysql::Grant<||>
    }

    case $module {
      'psick': {
        ::tp::install { 'icingaweb2' :
          ensure      => $ensure,
          auto_prereq => $auto_prereq,
        }
        if $template {
          ::tp::conf { 'icingaweb2':
            ensure       => $ensure,
            template     => $template,
            base_dir     => 'conf',
            options_hash => $options,
          }
        }
        $tp_conf_defaults = {
          ensure        => $ensure,
          options_hash  => $options,
        }
        $tp_conf_hash.each |$k,$v| {
          ::tp::conf { $k:
            * => $tp_conf_defaults + $v,
          }
        }
      }
      'icinga': {
        $db_type = $db_backend ? {
          'mariadb' => 'mysql',
          'mysql'   => 'mysql',
          'pgsql'   => 'pgsql',
        }
        $default_icingaweb2_params = $db_manage ? {
          true  => {
            import_schema  => true,
            db_type        => $db_type,
            db_host        => $db_settings['host'],
            db_username    => $db_settings['user'],
            db_password    => $db_settings['password'],
            config_backend => $config_backend,
          },
          false => {
            config_backend => $config_backend,
          },
        }
        class { '::icingaweb2':
          * => $default_icingaweb2_params + $icingaweb2_params,
        }
        if $auto_prereq and $::osfamily == 'RedHat' {
          tp::install { 'scl':
            before => [ Package['icingaweb2'] , Class['psick::php::fpm'] ],
          }
        }

        if $api_user_manage {
          icinga2::object::apiuser { $api_user:
            password    => $api_password,
            permissions => $api_user_permissions,
            target      => '/etc/icinga2/conf.d/api-users.conf',
          }
        }

        if $monitoring_module_manage {
          $monitoring_module_defaults = {
            ensure            => $ensure,
            ido_type          => $db_type,
            ido_host          => $ido_settings['host'],
            ido_db_name       => $ido_settings['database'],
            ido_db_username   => $ido_settings['user'],
            ido_db_password   => $ido_settings['password'],
            commandtransports => {
              icinga2 => {
                transport => 'api',
                username  => $api_user,
                password  => $api_password,
              }
            }
          }
          class { 'icingaweb2::module::monitoring':
            * => $monitoring_module_defaults + $monitoring_module_params,
          }
        }

        if $puppetdb_module_manage {
          $puppetdb_module_defaults = {
            ensure => $ensure,
            ssl    => 'puppet',
            host   => $servername,
          }
          class { 'icingaweb2::module::puppetdb':
            * => $puppetdb_module_defaults + $puppetdb_module_params,
          }
        }

        if $director_module_manage {
          $director_db_type = $director_db_backend ? {
            'mariadb' => 'mysql',
            'mysql'   => 'mysql',
            'pgsql'   => 'pgsql',
          }
          $director_module_defaults = {
            ensure        => $ensure,
            db_type       => $director_db_type,
            db_host       => $director_db_settings['host'],
            db_name       => $director_db_settings['database'],
            db_username   => $director_db_settings['user'],
            db_password   => $director_db_settings['password'],
            import_schema => true,
            kickstart     => true,
            api_host      => $api_host,
            api_username  => $api_user,
            api_password  => $api_password,
            endpoint      => pick($::psick::icinga2::master,$clientcert),
          }
          class { 'icingaweb2::module::director':
            * => $director_module_defaults + $director_module_params,
          }
        }

        if $grafana_module_manage {
          $grafana_module_defaults = {
            ensure         => $ensure,
            git_repository => 'https://github.com/Mikesch-mp/icingaweb2-module-grafana',
            git_revision   => 'master',
            settings       => {},
          }
          icingaweb2::module { 'grafana':
            * => $grafana_module_defaults + $grafana_module_params,
          }
          if $grafana_manage {
            $grafana_defaults = {
              ensure          => $ensure,
              dashboards_hash => {
                'icinga2-default.json' => {
                  ensure   => $ensure,
                  template => undef,
                  source   => 'file:///etc/icingaweb2/enabledModules/grafana/dashboards/influxdb/icinga2-default.json',
                  editable => 'true', # lint:ignore:quoted_booleans
                  require  => Icingaweb2::Module['grafana'],
                },
                'base-metrics.json' => {
                  ensure   => $ensure,
                  template => undef,
                  source   => 'file:///etc/icingaweb2/enabledModules/grafana/dashboards/influxdb/base-metrics.json',
                  editable => 'true', # lint:ignore:quoted_booleans
                  require  => Icingaweb2::Module['grafana'],
                },
              },
              datasources_hash => {
                'DS_ICINGA2' => {
                  ensure           => $ensure,
                  file_name        => 'ds_icinga2.yaml',
                  template         => 'psick/grafana/datasource.yaml.erb',
                  type             => 'influxdb',
                  access           => 'proxy',
                  org_id           => '1',
                  database         => $influxdb_settings['database'],
                  user             => $influxdb_settings['user'],
                  url              => "http://${influxdb_settings['host']}:${influxdb_settings['port']}",
                  basic_authuser   => $grafana_settings['user'],
                  secure_json_data => {
                    password          => $influxdb_settings['password'],
                    basicAuthPassword => $grafana_settings['password'],
                  }
                }
              }
            }
            class { 'psick::grafana':
              * => $grafana_defaults + $grafana_params,
            }
            psick::grafana::user { $grafana_settings['user']:
              name           => $grafana_settings['user'],
              password       => $grafana_settings['password'],
              host           => $grafana_settings['host'],
              port           => $grafana_settings['port'],
              protocol       => $grafana_settings['protocol'],
              email          => $grafana_settings['email'],
              admin_user     => $grafana_settings['admin_user'],
              admin_password => $grafana_settings['admin_password'],
            }
          }
        }

        if $git_manage {
          include ::psick::git
        }
        $extra_modules.each |$k,$v| {
          class { "::icingaweb2::module::${k}":
            * => $v,
          }
        }
      }
      default: {}
    }

    if $db_manage {
      case $db_backend {
        'mariadb': {
          psick::mariadb::grant { 'icingaweb2':
            user       => $db_settings['user'],
            password   => $db_settings['password'],
            db         => $db_settings['database'],
            create_db  => $db_settings['create_db'],
            privileges => $db_settings['grant'],
            host       => $db_settings['host'],
            before     => Package['icingaweb2'],
          }
        }
        'mysql': {
          psick::mysql::grant { 'icingaweb2':
            user       => $db_settings['user'],
            password   => $db_settings['password'],
            db         => $db_settings['database'],
            create_db  => $db_settings['create_db'],
            privileges => $db_settings['grant'],
            host       => $db_settings['host'],
            before     => Package['icingaweb2'],
          }
        }
        'pgsql': {
          # puppetlabs-postgres module required
          postgresql::server::db { $db_settings['database']:
            user     => $db_settings['user'],
            password => postgresql_password($db_settings['user'], $db_settings['password']),
            before   => Package['icingaweb2'],
          }
        }
        default: { }
      } # END case $db_backend
    } # END if $db_manage 


    if $director_db_manage and $director_module_manage {
      case $director_db_backend {
        'mariadb': {
          psick::mariadb::grant { 'director_icingaweb2':
            user       => $director_db_settings['user'],
            password   => $director_db_settings['password'],
            db         => $director_db_settings['database'],
            create_db  => $director_db_settings['create_db'],
            privileges => $director_db_settings['grant'],
            host       => $director_db_settings['host'],
            before     => Package['icingaweb2'],
          }
        }
        'mysql': {
          psick::mysql::grant { 'director_icingaweb2':
            user       => $director_db_settings['user'],
            password   => $director_db_settings['password'],
            db         => $director_db_settings['database'],
            create_db  => $director_db_settings['create_db'],
            privileges => $director_db_settings['grant'],
            host       => $director_db_settings['host'],
            before     => Package['icingaweb2'],
          }
        }
        'pgsql': {
          # puppetlabs-postgres module required
          postgresql::server::db { $director_db_settings['database']:
            user     => $director_db_settings['user'],
            password => postgresql_password($director_db_settings['user'], $director_db_settings['password']),
            before   => Package['icingaweb2'],
          }
        }
        default: { }
      } # END case $diretor_db_backend
    } # END if $director_db_manage 

    if $db_backend {
      $camel_db_backend = $db_backend ? {
        'mariadb' => 'Mysql',
        'mysql'   => 'Mysql',
        'pgsql'   => 'Pgsql',
      }
      $zend_package_require = $::osfamily ? {
        'RedHat' => Tp::Install['epel'],
        default  => undef,
      }
      package { "php-ZendFramework-Db-Adapter-Pdo-${camel_db_backend}":
        before  => Package['icingaweb2'],
        require => $zend_package_require,
      }
    }

    if $fix_php_timezone {
      augeas { 'php_date_timezone':
        context => '/files/etc/php.ini/DATE',
        changes => [
          "set date.timezone ${::psick::timezone}",
        ],
      }
    }
    if $::selinux and $install_icingaweb2_selinux {
      package { 'icingaweb2-selinux':
        ensure  => $ensure,
        require => Class['icinga2'],
      }
    }

    if $php_fpm_manage {
      class { 'psick::php::fpm':
        package_name => $php_fpm_name,
        service_name => $php_fpm_name,
        subscribe    => Class['icingaweb2'],
      }

    }
  }
}