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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 
       | 
      
        # File 'manifests/server.pp', line 14
class prometheus::server (
  String $hostname,
  String $tls_account,
  String $grafana_password,
  String $retention = '15d',
  Array[Hash] $targets = {},
  Optional[String] $tls_challengealias = undef,
  Optional[String] $backup_target = undef,
  Optional[String] $backup_watchdog = undef,
  Optional[String] $backup_password = undef,
  Optional[Hash[String, String]] $backup_environment = undef,
  Optional[String] $backup_rclone = undef,
) {
  package { 'prometheus': }
  file { '/etc/conf.d/prometheus':
    ensure  => file,
    content => template('prometheus/conf.erb'),
    require => Package['prometheus'],
    notify  => Service['prometheus'],
  }
  file { '/etc/prometheus/prometheus.yml':
    ensure  => file,
    content => template('prometheus/prometheus.yml.erb'),
    require => Package['prometheus'],
    notify  => Service['prometheus'],
  }
  file { '/etc/prometheus/servers_node.yml':
    ensure  => file,
    content => template('prometheus/servers_node.yml.erb'),
    require => Package['prometheus'],
    notify  => Service['prometheus'],
  }
  file { '/etc/prometheus/servers_wireguard.yml':
    ensure  => file,
    content => template('prometheus/servers_wireguard.yml.erb'),
    require => Package['prometheus'],
    notify  => Service['prometheus'],
  }
  file { '/etc/prometheus/servers_systemd.yml':
    ensure  => file,
    content => template('prometheus/servers_systemd.yml.erb'),
    require => Package['prometheus'],
    notify  => Service['prometheus'],
  }
  file { '/etc/prometheus/blackbox_http.yml':
    ensure  => file,
    content => template('prometheus/blackbox_http.yml.erb'),
    require => Package['prometheus'],
    notify  => Service['prometheus'],
  }
  service { 'prometheus':
    ensure => running,
    enable => true,
  }
  nginx::site { $hostname:
    proxy_target       => 'http://localhost:9090',
    tls_challengealias => $tls_challengealias,
    tls_account        => $tls_account,
    users              => {
      'grafana'  => $grafana_password,
    },
  }
  package { 'prometheus-blackbox-exporter': }
  -> file { '/etc/prometheus/blackbox.yml':
    ensure => file,
    source => 'puppet:///modules/prometheus/blackbox.yml',
  }
  ~> service { 'prometheus-blackbox-exporter':
    ensure => running,
    enable => true,
  }
  if $backup_target != '' {
    backup::repo { 'prometheus':
      source        => '/var/lib/prometheus',
      target        => $backup_target,
      watchdog_url  => $backup_watchdog,
      password      => $backup_password,
      environment   => $backup_environment,
      rclone_config => $backup_rclone,
    }
  }
}
       |