Puppet Class: alertmanager

Defined in:
modules/alertmanager/manifests/init.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • active_host (Stdlib::Host)
  • partners (Array[Stdlib::Host])
  • irc_channel (String)
  • victorops_api_key (Optional[String]) (defaults to: undef)
  • vhost (Optional[String]) (defaults to: 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
# File 'modules/alertmanager/manifests/init.pp', line 2

class alertmanager (
    Stdlib::Host        $active_host,
    Array[Stdlib::Host] $partners,
    String $irc_channel,
    Optional[String] $victorops_api_key = undef,
    Optional[String] $vhost = undef,
) {
    ensure_packages(['prometheus-alertmanager', 'alertmanager-webhook-logger'])

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

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

    # Build cluster peers argv with all non-local hostnames
    $all_hosts = $partners + $active_host
    $cluster_opts = $all_hosts.reduce(
      ['--cluster.advertise-address', "${::ipaddress}:9094"]) |$agg, $host| {
        if $host != $::fqdn {
            $tmp = ['--cluster.peer', "${host}:9094"]
        } else {
            $tmp = []
        }
        $agg + $tmp
    }

    if (empty($cluster_opts)) {
        $args = ''
    } else {
        $args = join($cluster_opts, ' ')
    }

    file { '/etc/default/prometheus-alertmanager':
        ensure  => present,
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        content => "ARGS=\"${args}\"\n",
        notify  => Service['prometheus-alertmanager'],
    }

    file { '/etc/prometheus/alertmanager.yml':
        ensure       => present,
        owner        => 'prometheus',
        group        => 'root',
        mode         => '0440',
        show_diff    => false,
        content      => template('alertmanager/alertmanager.yml.erb'),
        notify       => Exec['alertmanager-reload'],
        validate_cmd => '/usr/bin/amtool check-config %',
    }

    # Custom email template -- adapted from upstream to adjust for "alert dashboard" links.
    file { '/etc/prometheus/alertmanager_templates/email.tmpl':
        ensure    => present,
        owner     => 'prometheus',
        group     => 'root',
        mode      => '0440',
        show_diff => false,
        content   => template('alertmanager/email.tmpl.erb'),
        notify    => Exec['alertmanager-reload'],
    }

    exec { 'alertmanager-reload':
        command     => '/bin/systemctl reload prometheus-alertmanager',
        refreshonly => true,
    }
}