Puppet Plan: patching::monitoring_prometheus

Defined in:
plans/monitoring_prometheus.pp

Summary

Create or remove alert silences for hosts in Prometheus.

Overview

Examples:

Remote target definition for $monitoring_target

vars:
  patching_monitoring_target: 'prometheus'
  patching_monitoring_silence_duration: 24
  patching_monitoring_silence_units: 'hours'

groups:
  - name: prometheus
    config:
      transport: remote
      remote:
        username: 'domain\prom_user'
        password:
          _plugin: pkcs7
          encrypted_value: >
            ENC[PKCS7,xxx]
    targets:
      - prometheus.domain.tld

Parameters:

  • targets (TargetSpec)

    Set of targets to run against.

  • action (Enum['enable', 'disable'])

    What action to perform on the monitored targets:

    - `enable` Resumes monitoring alerts
    - 'disable' Supresses monitoring alerts
    
  • monitoring_silence_duration (Optional[Integer]) (defaults to: undef)

    How long the alert silence will be alive for

  • monitoring_silence_units (Optional[Enum['minutes', 'hours', 'days', 'weeks']]) (defaults to: undef)

    Goes with the silence duration to determine how long the alert silence will be alive for

  • monitoring_target (Optional[TargetSpec]) (defaults to: undef)

    Name or reference to the remote transport target of the Prometheus server. The remote transport should have the following properties:

    - [String] username
        Username for authenticating with Prometheus
    - [Password] password
        Password for authenticating with Prometheus
    
  • noop (Boolean) (defaults to: false)

    Flag to enable noop mode. When noop mode is enabled no snapshots will be created or deleted.



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
# File 'plans/monitoring_prometheus.pp', line 48

plan patching::monitoring_prometheus (
  TargetSpec                                          $targets,
  Enum['enable', 'disable']                           $action,
  Optional[Integer]                                   $monitoring_silence_duration = undef,
  Optional[Enum['minutes', 'hours', 'days', 'weeks']] $monitoring_silence_units = undef,
  Optional[TargetSpec]                                $monitoring_target = undef,
  Boolean                                             $noop = false,
) {
  $_targets = run_plan('patching::get_targets', $targets)
  $group_vars = $_targets[0].vars

  # Set the silence to last for 2 hours by default
  $_monitoring_silence_duration = pick($monitoring_silence_duration,
                                  $group_vars['patching_monitoring_silence_duration'],
                                  2)
  $_monitoring_silence_units = pick($monitoring_silence_units,
                                $group_vars['patching_monitoring_silence_units'],
                                'hours')
  $_monitoring_target = pick($monitoring_target,
                        $group_vars['patching_monitoring_target'],
                        'prometheus')

  # Create array of node names
  $target_names = patching::target_names($_targets, 'name')

  # Display status message
  case $action {
    'enable': {
      out::message('Enabling monitoring for:')
      $target_names.each |$n| {
        out::message(" + ${n}")
      }
    }
    'disable': {
      out::message('Disabling monitoring for:')
      $target_names.each |$n| {
        out::message(" - ${n}")
      }
    }
    default: {
      fail_plan("Unknown action: ${action}")
    }
  }

  if !$noop {
    run_task('patching::monitoring_prometheus', $_monitoring_target,
      targets           => $target_names,
      action            => $action,
      prometheus_server => get_target($_monitoring_target).uri,
      silence_duration  => $_monitoring_silence_duration,
      silence_units     => $_monitoring_silence_units,
    )
  }
}