Defined Type: netops::prometheus::hosts

Defined in:
modules/netops/manifests/prometheus/hosts.pp

Overview

Parameters:

  • targets (Prometheus::Blackbox::SmokeHosts)
  • targets_file (String)
  • extra_labels (Hash[String, String]) (defaults to: {})


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
# File 'modules/netops/manifests/prometheus/hosts.pp', line 12

define netops::prometheus::hosts (
  Prometheus::Blackbox::SmokeHosts $targets,
  String $targets_file,
  Hash[String, String] $extra_labels = {},
) {
  $out = $targets.reduce([]) |$memo, $el| {
    $host = $el[0]
    $config = $el[1]

    $addresses = dnsquery::lookup($host, true)
    if $addresses.empty() {
      fail("netops::prometheus::hosts: no addresses found for '${host}'")
    }

    $probes = $addresses.map |$ip| {
      $family = wmflib::ip_family($ip)

      $ret = {
        targets => ["${host}:0@${ip}"],
        labels  => {
          module      => "icmp_ip${family}",
          family      => "ip${family}",
          address     => $ip,
          realm       => $config['realm'],
          rack        => $config['rack'],
          role        => 'host',
          # Not strictly required, but make sure all metrics (in this job)
          # have the same set of labels.
          target_site => $config['site'],
        } + $extra_labels,
      }

      $ret
    }

    $memo + $probes
  }

  file { $targets_file:
    content => to_yaml(flatten($out)),
  }
}