Puppet Class: psick::icinga2

Defined in:
manifests/icinga2.pp

Overview

This profile manages the installation and configuration of icinga2 via the the upstream Icinga2 module. If exposes parameters to allow easy configuration and automation on a setup based on icinga client on nodes and icinga server, with options to automatically populate, and override, data retrived from PuppetDB to build the hosts and services checks. It also automatically configures database integration taking care of grants and db users.

Parameters:

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

    If to install or remove icinga2

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

    If to actually manage any resource in this profile or not

  • 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.

  • master (String) (defaults to: "icinga.${::domain}")
  • is_client (Boolean) (defaults to: true)
  • is_server (Boolean) (defaults to: false)
  • icinga2_class_params (Hash) (defaults to: {})
  • manage_api_feature (Boolean) (defaults to: true)
  • icinga2_feature_api_class_params (Hash) (defaults to: {})
  • client_features (Array) (defaults to: ['checker','mainlog'])
  • server_features (Array) (defaults to: ['checker','mainlog','notification','command'])
  • influxdb_manage (Boolean) (defaults to: true)
  • influxdb_settings (Hash) (defaults to: {})
  • ido_manage (Boolean) (defaults to: true)
  • ido_backend (Enum['mariadb','mysql','pgsql']) (defaults to: 'mariadb')
  • ido_settings (Hash) (defaults to: {})
  • generate_client_zones_file (Boolean) (defaults to: true)
  • puppetdb_hosts_import (Boolean) (defaults to: true)
  • puppetdb_hosts_details_import (Boolean) (defaults to: true)
  • puppetdb_zones_import (Boolean) (defaults to: true)
  • puppetdb_hosts_override_hash (Hash) (defaults to: {})
  • puppetdb_zones_override_hash (Hash) (defaults to: {})
  • puppetdb_endpoints_override_hash (Hash) (defaults to: {})
  • notes_url_prefix (String) (defaults to: "https://${servername}/#/inspect/node/")
  • notes_url_suffix (String) (defaults to: '/reports')
  • puppetdb_fact_address (String) (defaults to: 'networking.ip')
  • puppetdb_fact_address6 (String) (defaults to: 'networking.ip6')
  • puppetdb_fact_network (String) (defaults to: 'network')
  • puppetdb_fact_role (String) (defaults to: 'role')
  • puppetdb_fact_env (String) (defaults to: 'env')
  • config_hash (Hash) (defaults to: {})
  • endpoint_hash (Hash) (defaults to: {})
  • endpoint_default_params (Hash) (defaults to: {})
  • zone_hash (Hash) (defaults to: {})
  • zone_default_params (Hash) (defaults to: {})
  • apiuser_hash (Hash) (defaults to: {})
  • apiuser_default_params (Hash) (defaults to: {})
  • checkcommand_hash (Hash) (defaults to: {})
  • checkcommand_default_params (Hash) (defaults to: {})
  • host_hash (Hash) (defaults to: {})
  • host_default_params (Hash) (defaults to: {})
  • hostgroup_hash (Hash) (defaults to: {})
  • hostgroup_default_params (Hash) (defaults to: {})
  • dependency_hash (Hash) (defaults to: {})
  • dependency_default_params (Hash) (defaults to: {})
  • timeperiod_hash (Hash) (defaults to: {})
  • timeperiod_default_params (Hash) (defaults to: {})
  • usergroup_hash (Hash) (defaults to: {})
  • usergroup_default_params (Hash) (defaults to: {})
  • user_hash (Hash) (defaults to: {})
  • user_default_params (Hash) (defaults to: {})
  • notificationcommand_hash (Hash) (defaults to: {})
  • notificationcommand_default_params (Hash) (defaults to: {})
  • notification_hash (Hash) (defaults to: {})
  • notification_default_params (Hash) (defaults to: {})
  • service_hash (Hash) (defaults to: {})
  • service_default_params (Hash) (defaults to: {})
  • servicegroup_hash (Hash) (defaults to: {})
  • servicegroup_default_params (Hash) (defaults to: {})
  • scheduleddowntime_hash (Hash) (defaults to: {})
  • scheduleddowntime_default_params (Hash) (defaults to: {})
  • eventcommand_hash (Hash) (defaults to: {})
  • eventcommand_default_params (Hash) (defaults to: {})
  • checkresultreader_hash (Hash) (defaults to: {})
  • checkresultreader_default_params (Hash) (defaults to: {})


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
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'manifests/icinga2.pp', line 15

class psick::icinga2 (
  String          $ensure                  = 'present',
  Boolean         $manage                  = $::psick::manage,

  String           $master                 = "icinga.${::domain}",
  Boolean          $is_client              = true,
  Boolean          $is_server              = false,

  Hash $icinga2_class_params               = {},

  # API feature class is declared directly and should not added to these Arrays
  Boolean $manage_api_feature              = true,
  Hash $icinga2_feature_api_class_params   = {},
  Array $client_features                   = ['checker','mainlog'],
  Array $server_features                   = ['checker','mainlog','notification','command'],

  Boolean    $influxdb_manage              = true,
  Hash       $influxdb_settings            = {},

  Boolean         $ido_manage              = true,
  Enum['mariadb','mysql','pgsql'] $ido_backend = 'mariadb',
  Hash            $ido_settings            = {},

  Boolean $generate_client_zones_file      = true,

  Boolean $puppetdb_hosts_import           = true,
  Boolean $puppetdb_hosts_details_import   = true,
  Boolean $puppetdb_zones_import           = true,
  Hash $puppetdb_hosts_override_hash       = {},
  Hash $puppetdb_zones_override_hash       = {},
  Hash $puppetdb_endpoints_override_hash   = {},
  String $notes_url_prefix                 = "https://${servername}/#/inspect/node/",
  String $notes_url_suffix                 = '/reports',
  String $puppetdb_fact_address            = 'networking.ip',
  String $puppetdb_fact_address6           = 'networking.ip6',
  String $puppetdb_fact_network            = 'network',
  String $puppetdb_fact_role               = 'role',
  String $puppetdb_fact_env                = 'env',

  Hash $config_hash                        = {},

  Hash $endpoint_hash                      = {},
  Hash $endpoint_default_params            = {},

  Hash $zone_hash                          = {},
  Hash $zone_default_params                = {},

  Hash $apiuser_hash                       = {},
  Hash $apiuser_default_params             = {},

  Hash $checkcommand_hash                  = {},
  Hash $checkcommand_default_params        = {},

  Hash $host_hash                          = {},
  Hash $host_default_params                = {},

  Hash $hostgroup_hash                     = {},
  Hash $hostgroup_default_params           = {},

  Hash $dependency_hash                    = {},
  Hash $dependency_default_params          = {},

  Hash $timeperiod_hash                    = {},
  Hash $timeperiod_default_params          = {},

  Hash $usergroup_hash                     = {},
  Hash $usergroup_default_params           = {},

  Hash $user_hash                          = {},
  Hash $user_default_params                = {},

  Hash $notificationcommand_hash           = {},
  Hash $notificationcommand_default_params = {},

  Hash $notification_hash                  = {},
  Hash $notification_default_params        = {},

  Hash $service_hash                       = {},
  Hash $service_default_params             = {},

  Hash $servicegroup_hash                  = {},
  Hash $servicegroup_default_params        = {},

  Hash $scheduleddowntime_hash             = {},
  Hash $scheduleddowntime_default_params   = {},

  Hash $eventcommand_hash                  = {},
  Hash $eventcommand_default_params        = {},

  Hash $checkresultreader_hash             = {},
  Hash $checkresultreader_default_params   = {},

  Boolean         $no_noop             = false,
) {

  if $manage {
    if !$::psick::noop_mode and $no_noop {
      info('Forced no-noop mode in psick::icinga2')
      noop(false)
    }

    # Declares Icinga class with selected features
    $features = $is_server ? {
      true    => $server_features,
      default => $client_features,
    }
    $default_params = {
      features => $features,
      #      confd    => 'zones.d',
    }
    class { 'icinga2':
      * => $default_params + $icinga2_class_params
    }

    # Handle InfluxDB configuration
    if $influxdb_manage and $is_server {
      if $influxdb_settings['host'] == 'localhost'
      or $influxdb_settings['host'] == '127.0.0.1' {
        $influxdb_service_ensure = 'running'
        $influxdb_service_enable = true
      } else {
        $influxdb_service_ensure = 'stopped'
        $influxdb_service_enable = false
      }

      class { 'tp_profile::influxdb':
        settings_hash => {
          service_ensure => $influxdb_service_ensure,
          service_enable => $influxdb_service_enable,
        },
      }
      Class[tp_profile::influxdb] -> Psick::Influxdb::Database<||>

      psick::influxdb::database { 'icinga2':
        database        => $influxdb_settings['database'],
        server_host     => $influxdb_settings['host'],
        server_port     => $influxdb_settings['port'],
        server_user     => $influxdb_settings['influxdb_user'],
        server_password => $influxdb_settings['influxdb_password'],
      }
      psick::influxdb::user { 'icinga2':
        user            => $influxdb_settings['user'],
        password        => $influxdb_settings['password'],
        database        => $influxdb_settings['database'],
        server_host     => $influxdb_settings['host'],
        server_port     => $influxdb_settings['port'],
        server_user     => $influxdb_settings['influxdb_user'],
        server_password => $influxdb_settings['influxdb_password'],
        require         => Psick::Influxdb::Database['icinga2'],
      }
      psick::influxdb::grant { 'icinga2':
        user            => $influxdb_settings['user'],
        database        => $influxdb_settings['database'],
        server_host     => $influxdb_settings['host'],
        server_port     => $influxdb_settings['port'],
        server_user     => $influxdb_settings['influxdb_user'],
        server_password => $influxdb_settings['influxdb_password'],
        privilege       => $influxdb_settings['grant'],
        require         => Psick::Influxdb::User['icinga2'],
      }
      class { '::icinga2::feature::influxdb':
        host     => $influxdb_settings['host'],
        port     => $influxdb_settings['port'],
        username => $influxdb_settings['user'],
        password => $influxdb_settings['password'],
        database => $influxdb_settings['database'],
        require  => Psick::Influxdb::Grant['icinga2'],
      }
    }

    # Handle IDO configuration
    if $ido_manage and $is_server {
      case $ido_backend {
        'mysql': {
          psick::mysql::grant { 'icinga2':
            user       => $ido_settings['user'],
            password   => $ido_settings['password'],
            db         => $ido_settings['database'],
            create_db  => $ido_settings['create_db'],
            privileges => $ido_settings['grant'],
            host       => $ido_settings['host'],
          }
          class { '::icinga2::feature::idomysql':
            user          => $ido_settings['user'],
            password      => $ido_settings['password'],
            database      => $ido_settings['database'],
            import_schema => true,
            require       => Psick::Mysql::Grant['icinga2'],
          }
        }
        'mariadb': {
          psick::mariadb::grant { 'icinga2':
            user       => $ido_settings['user'],
            password   => $ido_settings['password'],
            db         => $ido_settings['database'],
            create_db  => $ido_settings['create_db'],
            privileges => $ido_settings['grant'],
            host       => $ido_settings['host'],
          }
          class { '::icinga2::feature::idomysql':
            user          => $ido_settings['user'],
            password      => $ido_settings['password'],
            database      => $ido_settings['database'],
            import_schema => true,
            require       => Psick::Mariadb::Grant['icinga2'],
          }
        }
        'pgsql': {
          # puppetlabs-postgres module required
          postgresql::server::db { $ido_settings['database']:
            user     => $ido_settings['user'],
            password => postgresql_password($ido_settings['user'], $ido_settings['password']),
          }
          class { '::icinga2::feature::idopgsql':
            user          => $ido_settings['user'],
            password      => $ido_settings['password'],
            database      => $ido_settings['database'],
            import_schema => true,
            require       => Postgresql::Server::Db[$ido_settings['database']],
          }
        }
        default: {}
      }
    }

    # PuppetDB nodes import
    # It's possible to customise via the hiera key psick::icinga2::puppetdb_hosts_override_hash
    # any host entry retrieved via PuppetDB. The above hash should have as
    # first level keys certnames matching the ones retrieved from PuppetDB
    # Values must be valid params of the icinga2::object::host define and
    # are deep merged with the default ones set via psick::icinga2::host_default_params
    if $is_server and ($puppetdb_hosts_import or $puppetdb_zones_import) {
      $nodes_query = 'nodes { deactivated is null }'
      $nodes = puppetdb_query($nodes_query)
      $nodes_list = $nodes.map |$node| { $node['certname'] }
    }
    if $is_server and $puppetdb_hosts_import {
      $nodes_list.each |$k| {
        if $puppetdb_hosts_details_import {
          $nodes_facts_query = "inventory[facts] { trusted.certname = '${k}' }"
          $nodes_facts = puppetdb_query($nodes_facts_query)
          $disks = $nodes_facts[0]['facts']['mountpoints'].map |$kk,$vv| {
            if ! $vv['filesystem'] in ['devtmpfs','hugetlbfs','mqueue','devpts','tmpfs','rpc_pipefs'] {
              { $kk => { 'disk_partions' => $kk, } }
            }
          }
          $puppetdb_params = {
            address      => getvar("nodes_facts.0.facts.${puppetdb_fact_address}"),
            address6     => getvar("nodes_facts.0.facts.${puppetdb_fact_address6}"),
            notes        => "${k} | ${nodes_facts[0][facts][operatingsystem]} ${nodes_facts[0][facts][operatingsystemrelease]}",
            notes_url    => "${notes_url_prefix}${k}${notes_url_suffix}",
            vars         => {
              os         => capitalize($nodes_facts[0]['facts']['kernel']),
              distro     => $nodes_facts[0]['facts']['os']['name'],
              # disks      => $disks,
              network    => getvar("nodes_facts.0.facts.${puppetdb_fact_network}"),
              virtual    => $nodes_facts[0]['facts']['virtual'],
              role       => getvar("nodes_facts.0.facts.${puppetdb_fact_role}"),
              env        => getvar("nodes_facts.0.facts.${puppetdb_fact_env}"),
            }
          }
        } else {
          $puppetdb_params = {}
        }
        $hiera_override = pick ($puppetdb_hosts_override_hash[$k],{} )
        ::icinga2::object::host { $k:
          * => deep_merge($host_default_params,$puppetdb_params,$hiera_override),
        }
      }
    }

    # PuppetDB management of endpoint and zones
    if $is_server and $puppetdb_zones_import {
      $nodes_list.each |$k| {
        $local_zones_params = {
          ensure    => $ensure,
          parent    => 'master',
          endpoints => [ $k ],
        }
        $hiera_zones_override = pick ($puppetdb_zones_override_hash[$k],{} )
        if $k != $master {
          ::icinga2::object::zone { $k:
            * => deep_merge($zone_default_params,$local_zones_params,$hiera_zones_override),
          }
        }

        $local_endpoints_params = {
          ensure => $ensure,
          host   => $k,
        }
        $hiera_endpoints_override = pick ($puppetdb_endpoints_override_hash[$k],{} )
        ::icinga2::object::endpoint { $k:
          * => deep_merge($endpoint_default_params,$local_endpoints_params,$hiera_endpoints_override),
        }
      }
    }

    # Zones configuration on clients and server
    # and API configuration
    if $generate_client_zones_file {
      if $is_server and $puppetdb_zones_import {
        $client_zones_hash = {
          'master' => {
            endpoints => [ $master ],
          }
        }
        $client_endpoints_hash = {}
      } else {
        $client_zones_hash = {
          'master' => {
            endpoints => [ $master ],
          },
          $::fqdn => {
            endpoints => [ $::fqdn ],
            parent    => 'master',
          }
        }
        $client_endpoints_hash = {
          $master => {
            host => $master,
          },
          $::fqdn => {
            host => $::fqdn,
          }
        }
      }
    } else {
      $client_endpoints_hash = undef
      $client_zones_hash = undef
    }

    if $manage_api_feature {
      $icinga2_feature_api_defaults = {
        endpoints => $client_endpoints_hash,
        zones     => $client_zones_hash,
      }
      class { 'icinga2::feature::api':
        * => $icinga2_feature_api_defaults + $icinga2_feature_api_class_params,
      }
    }

    # Configuration files
    $config_hash.each |$k,$v| {
      ::psick::icinga2::config { $k:
        * => $v,
      }
    }

    # Extra objects
    $endpoint_hash.each |$k,$v| {
      ::icinga2::object::endpoint { $k:
        * => $endpoint_default_params + $v,
      }
    }
    $zone_hash.each |$k,$v| {
      ::icinga2::object::zone { $k:
        * => $zone_default_params + $v,
      }
    }
    $apiuser_hash.each |$k,$v| {
      ::icinga2::object::apiuser { $k:
        * => $apiuser_default_params + $v,
      }
    }
    $checkcommand_hash.each |$k,$v| {
      ::icinga2::object::checkcommand { $k:
        * => $checkcommand_default_params + $v,
      }
    }
    $host_hash.each |$k,$v| {
      ::icinga2::object::host { $k:
        * => $host_default_params + $v,
      }
    }
    $hostgroup_hash.each |$k,$v| {
      ::icinga2::object::hostgroup { $k:
        * => $hostgroup_default_params + $v,
      }
    }
    $dependency_hash.each |$k,$v| {
      ::icinga2::object::dependency { $k:
        * => $dependency_default_params + $v,
      }
    }
    $timeperiod_hash.each |$k,$v| {
      ::icinga2::object::timeperiod { $k:
        * => $timeperiod_default_params + $v,
      }
    }
    $usergroup_hash.each |$k,$v| {
      ::icinga2::object::usergroup { $k:
        * => $usergroup_default_params + $v,
      }
    }
    $user_hash.each |$k,$v| {
      ::icinga2::object::user { $k:
        * => $user_default_params + $v,
      }
    }
    $notificationcommand_hash.each |$k,$v| {
      ::icinga2::object::notificationcommand { $k:
        * => $notificationcommand_default_params + $v,
      }
    }
    $notification_hash.each |$k,$v| {
      ::icinga2::object::notification { $k:
        * => $notification_default_params + $v,
      }
    }
    $service_hash.each |$k,$v| {
      ::icinga2::object::service { $k:
        * => $service_default_params + $v,
      }
    }
    $servicegroup_hash.each |$k,$v| {
      ::icinga2::object::servicegroup { $k:
        * => $servicegroup_default_params + $v,
      }
    }
    $scheduleddowntime_hash.each |$k,$v| {
      ::icinga2::object::scheduleddowntime { $k:
        * => $scheduleddowntime_default_params + $v,
      }
    }
    $eventcommand_hash.each |$k,$v| {
      ::icinga2::object::eventcommand { $k:
        * => $eventcommand_default_params + $v,
      }
    }
    $checkresultreader_hash.each |$k,$v| {
      ::icinga2::object::checkresultreader { $k:
        * => $checkresultreader_default_params + $v,
      }
    }

  } # END if $manage
}