Puppet Class: profile::wmcs::metricsinfra::alertmanager

Defined in:
modules/profile/manifests/wmcs/metricsinfra/alertmanager.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • alertmanager_hosts (Array[Stdlib::Fqdn]) (defaults to: lookup('profile::wmcs::metricsinfra::prometheus_alertmanager_hosts'))
  • active_host (Stdlib::Fqdn) (defaults to: lookup('profile::wmcs::metricsinfra::alertmanager_active_host'))
  • victorops_api_key (Optional[String[1]]) (defaults to: lookup('profile::wmcs::metricsinfra::victorops_api_key', {'default_value' => undef}))


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
# File 'modules/profile/manifests/wmcs/metricsinfra/alertmanager.pp', line 2

class profile::wmcs::metricsinfra::alertmanager (
    Array[Stdlib::Fqdn] $alertmanager_hosts = lookup('profile::wmcs::metricsinfra::prometheus_alertmanager_hosts'),
    Stdlib::Fqdn        $active_host        = lookup('profile::wmcs::metricsinfra::alertmanager_active_host'),
    Optional[String[1]] $victorops_api_key  = lookup('profile::wmcs::metricsinfra::victorops_api_key', {'default_value' => undef}),
) {
    $base_path = '/etc/prometheus/alertmanager'

    # Prometheus alert manager service setup and config
    package { 'prometheus-alertmanager':
        ensure => present,
    }

    exec { 'alertmanager-restart':
        require     => Package['prometheus-alertmanager'],
        command     => '/bin/systemctl restart prometheus-alertmanager',
        refreshonly => true,
    }

    $peers = $alertmanager_hosts.filter |Stdlib::Fqdn $host| {
        $host != $::fqdn
    }.map |Stdlib::Fqdn $host| {
        "${host}:9094"
    }

    file { '/etc/default/prometheus-alertmanager':
        content => epp(
          'profile/wmcs/metricsinfra/prometheus-alertmanager-defaults.epp',
          {
            'base_path'      => $base_path,
            'listen_address' => $::ipaddress,
            'peers'          => $peers,
          }
        ),
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        notify  => Exec['alertmanager-restart'],
    }

    # prometheus_configurator will manage the directory contents, but
    # it still needs to exist and be writable
    file { $base_path:
        ensure  => directory,
        owner   => 'prometheus',
        group   => 'prometheus',
        mode    => '0775',
        require => Package['prometheus-alertmanager'],
    }

    # TODO: instead of providing the config base, split into small
    # parts and fit into the base prometheus_configurator.pp config
    file { '/etc/prometheus-configurator/config.d/alertmanager-base.yaml':
        content => epp('profile/wmcs/metricsinfra/alertmanager.yml.epp', {
            victorops_api_key => $victorops_api_key,
        }),
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
    }

    profile::wmcs::metricsinfra::prometheus_configurator::output_config { 'alertmanager':
        kind    => 'alertmanager',
        options => {
            base_directory  => $base_path,
            units_to_reload => [
                'prometheus-alertmanager.service',
            ]
        },
    }

    service { 'prometheus-alertmanager':
        ensure => running,
    }
}