Puppet Class: icinga2

Defined in:
manifests/init.pp

Summary

This module installs and configures Icinga 2.

Overview

Note:

Setting manage_packages to false means that all package aren’t handeld by the module included the IDO packages.

Examples:

Declare icinga2 with all defaults. Keep in mind that your operating system may not have Icinga 2 in its package repository.


include icinga2

If you want to use the module icinga/puppet-icinga, e.g. to use the official Icinga Project repositories, enable the manage_repos parameter.

class { 'icinga2':
  manage_repos => true,
}

If you don’t want to manage the Icinga 2 service with puppet, you can dissable this behaviour with the manage_service parameter. When set to false no service refreshes will be triggered.

class { 'icinga2':
  manage_service => false,
}

To manage the version of Icinga 2 binaries you can do it by disable package management:

package { 'icinga2':
  ensure  => latest,
  notifiy => Class['icinga2'],
}

class { 'icinga2':
  manage_packages => false,
}

To set constants in etc/icinga2/constants.conf use the constants parameter and as value a hash, every key will be set as constant and assigned by it’s value. Defaults can be overwritten.

class { 'icinga2':
  ...
  constants   => {
    'key1'             => 'value1',
    'key2'             => 'value2',
    'PluginContirbDir' => '/usr/local/nagios/plugins',
  }
}

Enabling features with there defaults or loading parameters via Hiera:

class { 'icinga2':
  manage_repos => true,
  features     => ['checker', 'mainlog', 'command'],
}

The ITL contains several CheckCommand definitions to load, set these in the array of the plugins parameter, i.e. for a master or satellite do the following and disbale the load of the configuration in conf.d.

class { 'icinga':
  ...
  plugins => [ 'plugins', 'contrib-plugins', 'nscp', 'windows-plugins' ],
  confd   => false,
}

Sometimes it’s necessary to cover very special configurations that you cannot handle with this module. In this case you can use the icinga2::config::file tag on your file resource. This module collects all file resource types with this tag and triggers a reload of Icinga 2 on a file change.

include ::icinga2

file { '/etc/icinga2/conf.d/foo.conf':
  ensure => file,
  owner  => icinga,
  ...
  tag    => 'icinga2::config::file',
  ...
}

To use a different directory for your configuration, create the directory as file resource with tag icinga2::config::file.

file { '/etc/icinga2/local.d':
  ensure => directory,
  tag    => 'icinga2::config::file'
}
class { 'icinga2':
  ...
  confd => 'local.d',
}

Parameters:

  • ensure (Stdlib::Ensure::Service) (defaults to: running)

    Manages if the service should be stopped or running.

  • enable (Boolean) (defaults to: true)

    If set to true the Icinga 2 service will start on boot.

  • manage_repos (Boolean) (defaults to: false)

    When set to true this module will use the module icinga/puppet-icinga to manage repositories, e.g. the release repo on packages.icinga.com repository by default, the EPEL repository or Backports. For more information, see github.com/icinga/puppet-icinga.

  • manage_packages (Boolean) (defaults to: true)

    If set to false packages aren’t managed.

  • manage_selinux (Boolean) (defaults to: false)

    If set to true the icinga selinux package is installed if selinux is enabled. Also requires a ‘selinux_package_name` (icinga2::globals) and `manage_packages` has to be set to true.

  • manage_service (Boolean) (defaults to: true)

    If set to true the service is managed otherwise the service also isn’t restarted if a config file changed.

  • features (Array[String[1]])

    List of features to activate. Defaults to [checker, mainlog, notification].

  • purge_features (Boolean) (defaults to: true)

    Define if configuration files for features not managed by Puppet should be purged.

  • constants (Hash[String[1], Any]) (defaults to: {})

    Hash of constants. Defaults are set in the params class. Your settings will be merged with the defaults.

  • plugins (Array[String[1]])

    A list of the ITL plugins to load. Defaults to [ ‘plugins’, ‘plugins-contrib’, ‘windows-plugins’, ‘nscp’ ].

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

    ‘conf.d` is the directory where Icinga 2 stores its object configuration by default. To disable it, set this parameter to `false`. By default this parameter is `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.



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

class icinga2 (
  Array[String[1]]            $features,
  Array[String[1]]            $plugins,
  Stdlib::Ensure::Service     $ensure          = running,
  Boolean                     $enable          = true,
  Boolean                     $manage_repos    = false,
  Boolean                     $manage_packages = true,
  Boolean                     $manage_selinux  = false,
  Boolean                     $manage_service  = true,
  Boolean                     $purge_features  = true,
  Hash[String[1], Any]        $constants       = {},
  Variant[Boolean, String[1]] $confd           = true,
) {
  require icinga2::globals

  $selinux_package_name = $icinga2::globals::selinux_package_name

  # check selinux
  $_selinux = if fact('os.selinux.enabled') and $facts['os']['selinux']['enabled'] and $selinux_package_name {
    $manage_selinux
  } else {
    false
  }

  # load reserved words
  $_reserved = $icinga2::globals::reserved

  # merge constants with defaults
  $_constants = $icinga2::globals::constants + $constants

  # validate confd, boolean or string
  if $confd =~ Boolean {
    if $confd { $_confd = 'conf.d' } else { $_confd = undef }
  } else {
    $_confd = $confd
  }

  Class['icinga2::config']
  -> Concat <| tag == 'icinga2::config::file' |>
  ~> Class['icinga2::service']

  if $manage_repos {
    require icinga::repos
  }

  class { 'icinga2::install': }
  -> File <| ensure == 'directory' and tag == 'icinga2::config::file' |>
  -> class { 'icinga2::config': notify => Class['icinga2::service'] }
  -> File <| ensure != 'directory' and tag == 'icinga2::config::file' |>
  ~> class { 'icinga2::service': }
  contain icinga2::install
  contain icinga2::config
  contain icinga2::service

  include prefix($features, 'icinga2::feature::')
}