Puppet Class: prometheus::alertmanager

Inherits:
prometheus
Defined in:
manifests/alertmanager.pp

Summary

This module manages prometheus alertmanager

Overview

Example:

prometheus::alertmanager::time_intervals:
- name: weekend
  time_intervals:
    - weekdays: ['saturday','sunday']

Parameters:

  • arch (String[1]) (defaults to: $prometheus::real_arch)

    Architecture (amd64 or i386)

  • bin_dir (Stdlib::Absolutepath) (defaults to: $prometheus::bin_dir)

    Directory where binaries are located

  • config_file (Stdlib::Absolutepath)

    The path to put the configuration file

  • config_mode (String[1]) (defaults to: $prometheus::config_mode)

    The permissions of the configuration files

  • download_extension (String[1])

    Extension for the release binary archive

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

    Complete URL corresponding to the where the release binary archive can be downloaded

  • download_url_base (Prometheus::Uri)

    Base URL for the binary archive

  • extra_groups (Array)

    Extra groups to add the binary user to

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

    Extra options added to the startup command

  • global (Hash)

    The global alertmanager configuration. Example (also default): prometheus::alertmanager::global:

    smtp_smarthost: 'localhost:25'
    smtp_from: 'alertmanager@localhost'
    
  • group (String[1])

    Group under which the binary is running

  • inhibit_rules (Array)

    An array of inhibit rules. Example (also default): prometheus::alertmanager::inhibit_rules:

    • source_match:

      severity: 'critical'
      target_match:
        severity: 'warning'
      equal:
      - 'alertname'
      - 'cluster'
      - 'service'
      
  • init_style (Prometheus::Initstyle) (defaults to: $prometheus::init_style)

    Service startup scripts style (e.g. rc, upstart or systemd)

  • install_method (String[1]) (defaults to: $prometheus::install_method)

    Installation method: url or package (only url is supported currently)

  • manage_group (Boolean) (defaults to: true)

    Whether to create a group for or rely on external code for that

  • manage_service (Boolean) (defaults to: true)

    Should puppet manage the service? (default true)

  • manage_user (Boolean) (defaults to: true)

    Whether to create user or rely on external code for that

  • mute_time_intervals (Array[Hash])

    Array of mute time intervals Not applied if time_intervals is defined Example: prometheus::alertmanager::mute_time_intervals:

    • name: weekend time_intervals:

      - weekdays: ['saturday','sunday']
      
  • time_intervals (Array[Hash])

    Array of time intervals, only supported with 0.24.0 and newer

  • os (String[1]) (defaults to: $prometheus::os)

    Operating system (linux is the only one supported)

  • package_ensure (String[1])

    If package, then use this for package ensure default ‘latest’

  • package_name (String[1])

    The binary package name - not available yet

  • config_dir (Stdlib::Absolutepath)

    The directory to put the configuration files

  • purge_config_dir (Boolean) (defaults to: true)

    Purge config files no longer generated by Puppet

  • manage_config (Boolean) (defaults to: true)

    Whether Puppet should manage Alertmanager config

  • validate_config (Boolean) (defaults to: false)

    Whether Puppet should validate the config with amtool when it is not installed with the URL method

  • receivers (Array)

    An array of receivers. Example (also default): prometheus::alertmanager::receivers:

    • name: ‘Admin’ email_configs:

      - to: 'root@localhost'
      
  • restart_on_change (Boolean) (defaults to: true)

    Should puppet restart the service on configuration change? (default true)

  • reload_on_change (Boolean) (defaults to: false)

    Should puppet reload the service on configuration change? (default false)

  • route (Hash)

    The top level route. Example (also default): prometheus::alertmanager::route:

    group_by:
      - 'alertname'
      - 'cluster'
      - 'service'
    group_wait: '30s'
    group_interval: '5m'
    repeat_interval: '3h'
    receiver: 'Admin'
    
  • service_enable (Boolean) (defaults to: true)

    Whether to enable the service from puppet (default true)

  • service_ensure (Stdlib::Ensure::Service) (defaults to: 'running')

    State ensured for the service (default ‘running’)

  • service_name (String[1]) (defaults to: 'alertmanager')

    Name of the alertmanager service (default ‘alertmanager’)

  • storage_path (Stdlib::Absolutepath)

    The storage path to pass to the alertmanager. Defaults to ‘/var/lib/alertmanager’

  • templates (Array)

    The array of template files. Defaults to [ “$config_dir/*.tmpl” ]

  • user (String[1])

    User which runs the service

  • version (String[1])

    The binary release version

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

    Optional proxy server, with port number if needed. ie: example.com:8080

  • proxy_type (Optional[Enum['none', 'http', 'https', 'ftp']]) (defaults to: undef)

    Optional proxy server type (none|http|https|ftp)



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

class prometheus::alertmanager (
  Stdlib::Absolutepath $config_dir,
  Stdlib::Absolutepath $config_file,
  String[1] $download_extension,
  Prometheus::Uri $download_url_base,
  Array $extra_groups,
  Hash $global,
  String[1] $group,
  Array $inhibit_rules,
  String[1] $package_ensure,
  String[1] $package_name,
  Array $receivers,
  Hash $route,
  Array[Hash] $mute_time_intervals,
  Array[Hash] $time_intervals,
  Stdlib::Absolutepath $storage_path,
  Array $templates,
  String[1] $user,
  String[1] $version,
  Boolean $service_enable                                    = true,
  Stdlib::Ensure::Service $service_ensure                    = 'running',
  String[1] $service_name                                    = 'alertmanager',
  Boolean $restart_on_change                                 = true,
  Boolean $reload_on_change                                  = false,
  Boolean $purge_config_dir                                  = true,
  Boolean $manage_config                                     = true,
  Boolean $validate_config                                   = false,
  Prometheus::Initstyle $init_style                          = $prometheus::init_style,
  String[1] $install_method                                  = $prometheus::install_method,
  Boolean $manage_group                                      = true,
  Boolean $manage_service                                    = true,
  Boolean $manage_user                                       = true,
  String[1] $os                                              = $prometheus::os,
  Optional[String[1]] $extra_options                         = undef,
  Optional[String] $download_url                             = undef,
  String[1] $config_mode                                     = $prometheus::config_mode,
  String[1] $arch                                            = $prometheus::real_arch,
  Stdlib::Absolutepath $bin_dir                              = $prometheus::bin_dir,
  Optional[String[1]] $proxy_server                          = undef,
  Optional[Enum['none', 'http', 'https', 'ftp']] $proxy_type = undef,
) inherits prometheus {
  if( versioncmp($version, '0.3.0') == -1 ) {
    $real_download_url    = pick($download_url,
    "${download_url_base}/download/${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
  } else {
    $real_download_url    = pick($download_url,
    "${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
  }
  $notify_service = $restart_on_change ? {
    true    => Service[$service_name],
    default => undef,
  }

  $alertmanager_reload = $prometheus::init_style ? {
    'systemd'          => "systemctl reload-or-restart ${service_name}",
    /^(upstart|none)$/ => "service ${service_name} reload",
    /^(sysv|sles)$/    => "/etc/init.d/${service_name} reload",
    'launchd'          => "launchctl stop ${service_name} && launchctl start ${service_name}",
  }

  exec { 'alertmanager-reload':
    command     => $alertmanager_reload,
    path        => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
    refreshonly => true,
  }

  if $reload_on_change {
    $_notify_service = Exec['alertmanager-reload']
  } else {
    $_notify_service = $notify_service
  }

  file { $config_dir:
    ensure  => 'directory',
    owner   => 'root',
    group   => $group,
    purge   => $purge_config_dir,
    recurse => $purge_config_dir,
  }

  if (( versioncmp($version, '0.10.0') >= 0 ) and ( $install_method == 'url' )) {
    # If version >= 0.10.0 then install amtool - Alertmanager validation tool
    file { "${bin_dir}/amtool":
      ensure => link,
      target => "/opt/${package_name}-${version}.${os}-${arch}/amtool",
    }

    if $manage_config {
      file { $config_file:
        ensure       => file,
        owner        => 'root',
        group        => $group,
        mode         => $config_mode,
        content      => template('prometheus/alertmanager.yaml.erb'),
        notify       => $_notify_service,
        require      => File["${bin_dir}/amtool", $config_dir],
        validate_cmd => "${bin_dir}/amtool check-config --alertmanager.url='' %",
      }
    }
  } else {
    if $validate_config {
      $_validate_cmd = "${bin_dir}/amtool check-config --alertmanager.url='' %"
    } else {
      $_validate_cmd = undef
    }

    if $manage_config {
      file { $config_file:
        ensure       => file,
        owner        => 'root',
        group        => $group,
        mode         => $config_mode,
        content      => template('prometheus/alertmanager.yaml.erb'),
        notify       => $_notify_service,
        require      => File[$config_dir],
        validate_cmd => $_validate_cmd,
      }
    }
  }

  if $facts['prometheus_alert_manager_running'] == 'running' {
    # This is here to stop the previous alertmanager that was installed in version 0.1.14
    service { 'alert_manager':
      ensure => 'stopped',
    }
  }

  if $storage_path {
    file { $storage_path:
      ensure => 'directory',
      owner  => $user,
      group  => $group,
      mode   => '0755',
    }

    if( versioncmp($version, '0.12.0') == 1 ) {
      $options = "--config.file=${prometheus::alertmanager::config_file} --storage.path=${prometheus::alertmanager::storage_path} ${prometheus::alertmanager::extra_options}"
    } else {
      $options = "-config.file=${prometheus::alertmanager::config_file} -storage.path=${prometheus::alertmanager::storage_path} ${prometheus::alertmanager::extra_options}"
    }
  } else {
    if( versioncmp($prometheus::alertmanager::version, '0.12.0') == 1 ) {
      $options = "--config.file=${prometheus::alertmanager::config_file} ${prometheus::alertmanager::extra_options}"
    } else {
      $options = "-config.file=${prometheus::alertmanager::config_file} ${prometheus::alertmanager::extra_options}"
    }
  }

  prometheus::daemon { $service_name:
    install_method     => $install_method,
    version            => $version,
    download_extension => $download_extension,
    os                 => $os,
    arch               => $arch,
    real_download_url  => $real_download_url,
    bin_dir            => $bin_dir,
    notify_service     => $notify_service,
    package_name       => $package_name,
    package_ensure     => $package_ensure,
    manage_user        => $manage_user,
    user               => $user,
    extra_groups       => $extra_groups,
    group              => $group,
    manage_group       => $manage_group,
    purge              => $purge_config_dir,
    options            => $options,
    init_style         => $init_style,
    service_ensure     => $service_ensure,
    service_enable     => $service_enable,
    manage_service     => $manage_service,
    proxy_server       => $proxy_server,
    proxy_type         => $proxy_type,
  }
}