Puppet Class: icinga

Defined in:
manifests/init.pp

Summary

Configures the Icinga 2 Core and the api feature.

Overview

Parameters:

  • ca (Boolean)

    Enables a CA on this node.

  • this_zone (String)

    Name of the Icinga zone.

  • zones (Hash[String, Hash])

    All other zones.

  • ssh_key_type (Enum['dsa','ecdsa','ed25519','rsa']) (defaults to: 'rsa')

    SSH key type.

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

    The private key to install.

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

    The public key to install.

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

    The CA to send the certificate request to.

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

    Set the constants ‘TicketSalt` if `ca` is set to `true`. Otherwise the set value is used to authenticate the certificate request againt the CA on host `ca_server`.

  • logging_type (Enum['file', 'syslog']) (defaults to: 'file')

    Switch the log target. Only ‘file` is supported on Windows.

  • logging_level (Optional[Icinga::LogLevel]) (defaults to: undef)

    Set the log level.

  • cert_name (String) (defaults to: $facts['networking']['fqdn'])

    The certificate name to set as constant NodeName.

  • prepare_web (Boolean) (defaults to: false)

    Prepare to run Icinga Web 2 on the same machine. Manage a group ‘icingaweb2` and add the Icinga user to this group.

  • confd (Variant[Boolean, String]) (defaults to: false)

    ‘conf.d` is the directory where Icinga 2 stores its object configuration by default. To enable it, set this parameter to `true`. It’s also possible to assign your own directory. This directory must be managed outside of this module as file resource with tag icinga2::config::file.

  • extra_packages (Array[String]) (defaults to: [])


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
# File 'manifests/init.pp', line 49

class icinga (
  Boolean                              $ca,
  String                               $this_zone,
  Hash[String, Hash]                   $zones,
  Enum['dsa','ecdsa','ed25519','rsa']  $ssh_key_type    = 'rsa',
  Optional[Icinga::Secret]             $ssh_private_key = undef,
  Optional[String]                     $ssh_public_key  = undef,
  Optional[Stdlib::Host]               $ca_server       = undef,
  Optional[Icinga::Secret]             $ticket_salt     = undef,
  Array[String]                        $extra_packages  = [],
  Enum['file', 'syslog']               $logging_type    = 'file',
  Optional[Icinga::LogLevel]           $logging_level   = undef,
  String                               $cert_name       = $facts['networking']['fqdn'],
  Boolean                              $prepare_web     = false,
  Variant[Boolean, String]             $confd           = false,
) {
  assert_private()

  # CA uses const TicketSalt to set the ticket salt
  if $ca {
    if $ticket_salt {
      $_constants = { 'TicketSalt' => $ticket_salt, 'ZoneName' => $this_zone, 'NodeName' => $cert_name }
    } else {
      fail("Class[Icinga]: parameter 'ticket_salt' expects a String value if a CA is configured, got Undef")
    }
  } else {
    $_constants = { 'ZoneName' => $this_zone, 'NodeName' => $cert_name }
  }

  $manage_packages = $facts[os][family] ? {
    'redhat'  => false,
    'debian'  => false,
    'windows' => lookup('icinga2::manage_packages', undef, undef, true),
    'suse'    => false,
    default   => true,
  }

  class { 'icinga2':
    confd           => $confd,
    manage_packages => $manage_packages,
    constants       => lookup('icinga2::constants', undef, undef, {}) + $_constants,
    features        => [],
  }

  # switch logging between mainlog and syslog
  # logging on windows only file is supported, warning output see below
  if $logging_type == 'file' or $facts['kernel'] == 'windows' {
    $_mainlog = 'present'
    $_syslog  = 'absent'
  } else {
    $_mainlog = 'absent'
    $_syslog  = 'present'
  }

  class { 'icinga2::feature::mainlog':
    ensure   => $_mainlog,
    severity => $logging_level,
  }

  class { 'icinga2::feature::syslog':
    ensure   => $_syslog,
    severity => $logging_level,
  }

  case $facts['kernel'] {
    'linux': {
      $icinga_user    = $icinga2::globals::user
      $icinga_group   = $icinga2::globals::group
      $icinga_package = $icinga2::globals::package_name
      $icinga_home    = $icinga2::globals::spool_dir
      $icinga_service = $icinga2::globals::service_name

      if $ssh_public_key {
        $icinga_shell = '/bin/bash'
      } else {
        $icinga_shell = '/bin/false'
      }

      case $facts['os']['family'] {
        'redhat': {
          package { ['nagios-common', $icinga_package] + $extra_packages:
            ensure => installed,
            before => User[$icinga_user],
          }

          $icinga_user_groups = if $prepare_web {
            ['nagios', 'icingaweb2']
          } else {
            ['nagios']
          }
        }

        'debian': {
          package { [$icinga_package] + $extra_packages:
            ensure => installed,
            before => User['nagios'],
          }

          $icinga_user_groups = if $prepare_web {
            ['icingaweb2']
          } else {
            undef
          }
        }

        'suse': {
          package { [$icinga_package] + $extra_packages:
            ensure => installed,
            before => User['icinga'],
          }

          $icinga_user_groups = if $prepare_web {
            ['icingaweb2']
          } else {
            undef
          }
        }

        default: {
          fail("'Your operatingssystem ${::facts['os']['name']} is not supported'")
        }
      }

      if $prepare_web {
        group { 'icingaweb2':
          system => true,
        }

        Package['icinga2'] -> Exec['restarting icinga2'] -> Class['icinga2']

        exec { 'restarting icinga2':
          path        => $facts['path'],
          command     => "service ${icinga_service} restart",
          onlyif      => "service ${icinga_service} status",
          refreshonly => true,
          subscribe   => User[$icinga_user],
        }
      }

      user { $icinga_user:
        ensure => present,
        shell  => $icinga_shell,
        groups => $icinga_user_groups,
        before => Class['icinga2'],
      }

      if $ssh_public_key {
        ssh_authorized_key { "${icinga_user}@${$facts['networking']['fqdn']}":
          ensure => present,
          user   => $icinga_user,
          key    => $ssh_public_key,
          type   => $ssh_key_type,
        }
      } # pubkey

      if $ssh_private_key {
        file {
          default:
            ensure => file,
            owner  => $icinga_user,
            group  => $icinga_group;
          ["${icinga_home}/.ssh", "${icinga_home}/.ssh/controlmasters"]:
            ensure => directory,
            mode   => '0700';
          "${icinga_home}/.ssh/id_${ssh_key_type}":
            mode      => '0600',
            show_diff => false,
            content   => icinga::unwrap($ssh_private_key);
          "${icinga_home}/.ssh/config":
            content => "Host *\n  StrictHostKeyChecking no\n  ControlPath ${icinga_home}/.ssh/controlmasters/%r@%h:%p.socket\n  ControlMaster auto\n  ControlPersist 5m";
        }
      } # privkey
    } # Linux

    'windows': {
      $manage_repo = false

      if $logging_type != 'file' {
        fail('Only file is supported as logging_type on Windows')
      }
    }

    default: {
      fail("'Your operatingssystem ${::facts[os][name]} is not supported'")
    }
  } # kernel

  if $ca {
    include icinga2::pki::ca

    class { 'icinga2::feature::api':
      pki             => 'none',
      accept_config   => true,
      accept_commands => true,
      ticket_salt     => 'TicketSalt',
      zones           => {},
      endpoints       => {},
    }
  } else {
    if $ca_server {
      class { 'icinga2::feature::api':
        accept_config   => true,
        accept_commands => true,
        ca_host         => $ca_server,
        ticket_salt     => $ticket_salt,
        zones           => {},
        endpoints       => {},
      }
    }
  }

  $zones.each |String $zone, Hash $zone_attrs| {
    $zone_attrs.each|String $attr, $value| {
      if $attr == 'endpoints' {
        $value.each |String $endpoint, Hash $endpoint_attrs| {
          icinga2::object::endpoint { $endpoint:
            * => $endpoint_attrs,
          }
        }
      } # endpoints
    }

    icinga2::object::zone { $zone:
      * => $zone_attrs + { 'endpoints' => keys($zone_attrs['endpoints']) },
    }
  }
}