Defined Type: netops::prometheus::mgmt

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

Overview

Parameters:

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


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

define netops::prometheus::mgmt (
  Hash $targets,
  String $targets_file,
  Hash[String, String] $extra_labels = {},
) {
  # Invert $targets to get a rack -> host (singular) hash
  $rack_to_target = Hash(
    $targets.map |$k, $v| { [ $v['rack'], $k ] }
  )

  $out = $rack_to_target.reduce([]) |$memo, $el| {
    $rack = $el[0]
    $target = $el[1]

    $v4_address = ipresolve($target, 4)

    $ip4 = {
      targets => [$target],
      labels  => {
        module      => 'icmp_ip4',
        family      => 'ip4',
        address     => $v4_address,
        rack        => $rack,
        role        => 'mgmt',
      } + $extra_labels,
    }

    $memo + [$ip4]
  }

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