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[String]) (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[String]) (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[Icinga2::LogSeverity]) (defaults to: undef)

    Set the log level.

  • cert_name (String) (defaults to: $::fqdn)

    The certificate name to set as constant NodeName.

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


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

class icinga(
  Boolean                              $ca,
  String                               $this_zone,
  Hash[String, Hash]                   $zones,
  Enum['dsa','ecdsa','ed25519','rsa']  $ssh_key_type    = 'rsa',
  Optional[String]                     $ssh_private_key = undef,
  Optional[String]                     $ssh_public_key  = undef,
  Optional[Stdlib::Host]               $ca_server       = undef,
  Optional[String]                     $ticket_salt     = undef,
  Array[String]                        $extra_packages  = [],
  Enum['file', 'syslog']               $logging_type    = 'file',
  Optional[Icinga2::LogSeverity]       $logging_level   = undef,
  String                               $cert_name       = $::fqdn,
) {

  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           => false,
    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 $::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 $::kernel {
    'linux': {
      $icinga_user    = $::icinga2::globals::user
      $icinga_group   = $::icinga2::globals::group
      $icinga_package = $::icinga2::globals::package_name
      $icinga_home    = $::icinga2::globals::spool_dir

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

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

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

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

          user { 'nagios':
            ensure => present,
            shell  => $icinga_shell,
            before => Class['icinga2'],
          }
        } # Debian

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

          user { 'icinga':
            ensure => present,
            shell  => $icinga_shell,
            before => Class['icinga2'],
          }
        } # Suse

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

      if $ssh_public_key {
        ssh_authorized_key { "${icinga_user}@${::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',
            content => $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' {
        warning('Only file is support 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':
        pki             => 'icinga2',
        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']) }
    }
  }

}