Defined Type: netops::prometheus::icmp

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

Overview

$targets is the map of devices to target $targets_file is the path to write the result to $extra_labels is an hash to labels to attach to each target, in addition to labels derived from the config (address family, address, etc)

Parameters:

  • targets (Wmflib::Infra::Devices)
  • targets_file (String)
  • extra_labels (Hash[String, String]) (defaults to: {})


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

define netops::prometheus::icmp (
  Wmflib::Infra::Devices $targets,
  String $targets_file,
  Hash[String, String] $extra_labels = {},
) {

  $out = $targets.reduce([]) |$memo, $el| {
    $name = $el[0]
    $config = $el[1]

    if 'ipv4' in $config {
      $v4_address = $config['ipv4']
      $ip4 = {
        targets => [ "${name}:0@${v4_address}" ],
        labels => {
          module      => 'icmp_ip4',
          family      => 'ip4',
          target_site => $config['site'],
          role        => $config['role'],
          address     => $v4_address
        } + $extra_labels,
      }
    } else {
      $ip4 = {}
    }

    if 'ipv6' in $config {
      $v6_address = $config['ipv6']
      $ip6 = {
        targets => [ "${name}:0@${v6_address}" ],
        labels => {
          module      => 'icmp_ip6',
          family      => 'ip6',
          target_site => $config['site'],
          role        => $config['role'],
          address     => $v6_address
        } + $extra_labels,
      }
    } else {
      $ip6 = {}
    }

    $memo + [$ip4, $ip6]
  }

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