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,
)
}
}
|