Puppet Class: icinga2::feature::influxdb

Defined in:
manifests/feature/influxdb.pp

Summary

Configures the Icinga 2 feature influxdb.

Overview

Examples:

class { 'icinga2::feature::influxdb':
  host     => "10.10.0.15",
  username => "icinga2",
  password => "supersecret",
  database => "icinga2"
}

Parameters:

  • ensure (Enum['absent', 'present']) (defaults to: present)

    Set to present enables the feature influxdb, absent disables it.

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

    InfluxDB host address.

  • port (Optional[Stdlib::Port]) (defaults to: undef)

    InfluxDB HTTP port.

  • database (Optional[String[1]]) (defaults to: undef)

    InfluxDB database name.

  • username (Optional[String[1]]) (defaults to: undef)

    InfluxDB user name.

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

    InfluxDB user password. The password parameter isn’t parsed anymore.

  • basic_auth (Optional[Icinga2::BasicAuth]) (defaults to: undef)

    Username and password for HTTP basic authentication.

  • enable_ssl (Optional[Boolean]) (defaults to: undef)

    Either enable or disable SSL. Other SSL parameters are only affected if this is set to ‘true’.

  • ssl_noverify (Optional[Boolean]) (defaults to: undef)

    Disable TLS peer verification. Only valid if ssl is enabled.

  • ssl_key_path (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Location of the client private key. Only valid if ssl is enabled.

  • ssl_cert_path (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Location of the client certificate. Only valid if ssl is enabled.

  • ssl_cacert_path (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Location of the CA certificate. Only valid if ssl is enabled.

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

    The client private key in PEM format. Only valid if ssl is enabled.

  • ssl_cert (Optional[String[1]]) (defaults to: undef)

    The client certificate in PEM format. Only valid if ssl is enabled.

  • ssl_cacert (Optional[String[1]]) (defaults to: undef)

    The CA root certificate in PEM format. Only valid if ssl is enabled.

  • host_measurement (String[1]) (defaults to: '$host.check_command$')

    The value of this is used for the measurement setting in host_template.

  • host_tags (Hash[String[1], String[1]]) (defaults to: { hostname => '$host.name$' })

    Tags defined in this hash will be set in the host_template.

  • service_measurement (String[1]) (defaults to: '$service.check_command$')

    The value of this is used for the measurement setting in host_template.

  • service_tags (Hash[String[1], String[1]]) (defaults to: { hostname => '$host.name$', service => '$service.name$' })

    Tags defined in this hash will be set in the service_template.

  • enable_send_thresholds (Optional[Boolean]) (defaults to: undef)

    Whether to send warn, crit, min & max tagged data.

  • enable_send_metadata (Optional[Boolean]) (defaults to: undef)

    Whether to send check metadata e.g. states, execution time, latency etc.

  • flush_interval (Optional[Icinga2::Interval]) (defaults to: undef)

    How long to buffer data points before transfering to InfluxDB.

  • flush_threshold (Optional[Integer[1]]) (defaults to: undef)

    How many data points to buffer before forcing a transfer to InfluxDB.

  • enable_ha (Optional[Boolean]) (defaults to: undef)

    Enable the high availability functionality. Only valid in a cluster setup.



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
# File 'manifests/feature/influxdb.pp', line 84

class icinga2::feature::influxdb (
  Enum['absent', 'present']                     $ensure                 = present,
  Optional[Stdlib::Host]                        $host                   = undef,
  Optional[Stdlib::Port]                        $port                   = undef,
  Optional[String[1]]                              $database               = undef,
  Optional[String[1]]                              $username               = undef,
  Optional[Icinga::Secret]                      $password               = undef,
  Optional[Icinga2::BasicAuth]                  $basic_auth             = undef,
  Optional[Boolean]                             $enable_ssl             = undef,
  Optional[Boolean]                             $ssl_noverify           = undef,
  Optional[Stdlib::Absolutepath]                $ssl_key_path           = undef,
  Optional[Stdlib::Absolutepath]                $ssl_cert_path          = undef,
  Optional[Stdlib::Absolutepath]                $ssl_cacert_path        = undef,
  Optional[Icinga::Secret]                      $ssl_key                = undef,
  Optional[String[1]]                           $ssl_cert               = undef,
  Optional[String[1]]                           $ssl_cacert             = undef,
  String[1]                                     $host_measurement       = '$host.check_command$',
  Hash[String[1], String[1]]                    $host_tags              = { hostname => '$host.name$' },
  String[1]                                     $service_measurement    = '$service.check_command$',
  Hash[String[1], String[1]]                    $service_tags           = { hostname => '$host.name$', service => '$service.name$' },
  Optional[Boolean]                             $enable_send_thresholds = undef,
  Optional[Boolean]                             $enable_send_metadata   = undef,
  Optional[Icinga2::Interval]                   $flush_interval         = undef,
  Optional[Integer[1]]                          $flush_threshold        = undef,
  Optional[Boolean]                             $enable_ha              = undef,
) {
  if ! defined(Class['icinga2']) {
    fail('You must include the icinga2 base class before using any icinga2 feature class!')
  }

  $owner    = $icinga2::globals::user
  $group    = $icinga2::globals::group
  $conf_dir = $icinga2::globals::conf_dir
  $ssl_dir  = $icinga2::globals::cert_dir

  $_notify  = $ensure ? {
    'present' => Class['icinga2::service'],
    default   => undef,
  }

  if $basic_auth {
    $_basic_auth = if $basic_auth['password'] =~ String {
      $basic_auth + { 'password' => Sensitive($password) }
    } elsif $basic_auth['password'] =~ Sensitive {
      $basic_auth
    }
  } else {
    $_basic_auth = undef
  }

  $_password = if $password =~ Sensitive {
    $password
  } elsif $password =~ String {
    Sensitive($password)
  } else {
    undef
  }

  $host_template    = { measurement => $host_measurement, tags => $host_tags }
  $service_template = { measurement => $service_measurement, tags => $service_tags }

  if $enable_ssl {
    $cert = icinga::cert::files(
      'InfluxdbWriter_influxdb',
      $ssl_dir,
      $ssl_key_path,
      $ssl_cert_path,
      $ssl_cacert_path,
      $ssl_key,
      $ssl_cert,
      $ssl_cacert,
    )

    $attrs_ssl = {
      'ssl_enable'            => true,
      'ssl_insecure_noverify' => $ssl_noverify,
      'ssl_ca_cert'           => $cert['cacert_file'],
      'ssl_cert'              => $cert['cert_file'],
      'ssl_key'               => $cert['key_file'],
    }

    # Workaround, icinga::cert doesn't accept undef values for owner and group!
    if $facts['os']['family'] != 'windows' {
      icinga::cert { 'InfluxdbWriter_influxdb':
        args   => $cert,
        owner  => $owner,
        group  => $group,
        notify => $_notify,
      }
    } else {
      icinga::cert { 'InfluxdbWriter_influxdb':
        args   => $cert,
        owner  => 'foo',
        group  => 'bar',
        notify => $_notify,
      }
    }
  } else {
    $attrs_ssl = {
      'ssl_enable'            => undef,
      'ssl_insecure_noverify' => undef,
      'ssl_ca_cert'           => undef,
      'ssl_cert'              => undef,
      'ssl_key'               => undef,
    }
    $cert = {}
  }

  $attrs = {
    'host'                   => $host,
    'port'                   => $port,
    'database'               => $database,
    'username'               => $username,
    'password'               => $_password,
    'basic_auth'             => $_basic_auth,
    'host_template'          => $host_template,
    'service_template'       => $service_template,
    'enable_send_thresholds' => $enable_send_thresholds,
    'enable_send_metadata'   => $enable_send_metadata,
    'flush_interval'         => $flush_interval,
    'flush_threshold'        => $flush_threshold,
    'enable_ha'              => $enable_ha,
  }

  # create object
  icinga2::object { 'icinga2::object::InfluxdbWriter::influxdb':
    object_name => 'influxdb',
    object_type => 'InfluxdbWriter',
    attrs       => delete_undef_values($attrs + $attrs_ssl),
    attrs_list  => concat(keys($attrs), keys($attrs_ssl)),
    target      => "${conf_dir}/features-available/influxdb.conf",
    notify      => $_notify,
    order       => 10,
  }

  icinga2::feature { 'influxdb':
    ensure => $ensure,
  }
}