Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mute_time_intervals for Alertmanager #563

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ prometheus::alertmanager::route:
'group_interval': '5m'
'repeat_interval': '3h'
'receiver': 'Admin'
prometheus::alertmanager::mute_time_intervals: []
prometheus::alertmanager::storage_path: '/var/lib/alertmanager'
prometheus::alertmanager::templates: [ "%{lookup('prometheus::alertmanager::config_dir')}/*.tmpl" ]
prometheus::alertmanager::user: 'alertmanager'
Expand Down
7 changes: 7 additions & 0 deletions manifests/alertmanager.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
# Should puppet manage the service? (default true)
# @param manage_user
# Whether to create user or rely on external code for that
# @param mute_time_intervals
# Array of mute time intervals
# Example:
# prometheus::alertmanager::mute_time_intervals:
# - name: weekend
# weekdays: ['saturday','sunday']
# @param os
# Operating system (linux is the only one supported)
# @param package_ensure
Expand Down Expand Up @@ -103,6 +109,7 @@
String[1] $package_name,
Array $receivers,
Hash $route,
Array[Hash] $mute_time_intervals,
Stdlib::Absolutepath $storage_path,
Array $templates,
String[1] $user,
Expand Down
26 changes: 26 additions & 0 deletions spec/classes/alertmanager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Service[alertmanager]')
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', ['---', 'global:', ' smtp_smarthost: localhost:25', ' smtp_from: alertmanager@localhost'])
}
it {
is_expected.not_to contain_file('/etc/alertmanager/alertmanager.yaml').with_content(%r{mute_time_intervals})
}
end
describe 'service reload' do
it {
Expand All @@ -47,6 +50,29 @@
end
end

context 'with latest version specified and mute_time_intervals' do
let(:params) do
{
version: '0.22.0',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url',
mute_time_intervals: [{ 'name' => 'weekend', 'weekdays' => ['saturday','sunday'] }],
}
end

it {
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', [
'mute_time_intervals:',
'- name: weekend',
' weekdays:',
' - saturday',
' - sunday',
])
}
end

context 'when reload_on_change => true' do
let(:params) { { reload_on_change: true } }

Expand Down
5 changes: 5 additions & 0 deletions templates/alertmanager.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
<% receivers = scope.lookupvar('::prometheus::alertmanager::receivers') -%>
<% inhibit_rules = scope.lookupvar('::prometheus::alertmanager::inhibit_rules') -%>
<% full_config = { 'global'=>global, 'templates'=>templates, 'route'=>route, 'receivers'=>receivers, 'inhibit_rules'=>inhibit_rules } -%>
<%
if scope.function_versioncmp([scope.lookupvar('::prometheus::alertmanager::version'), '0.22.0']) >= 0
full_config['mute_time_intervals'] = scope.lookupvar('::prometheus::alertmanager::mute_time_intervals')
end
-%>
<%= full_config.to_yaml -%>